Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. public ActionResult PickGroupForHomework(PickGroupForHomeworkViewModel model)
  2.         {
  3.             ClassDeclarationsDBEntities6 entities = new ClassDeclarationsDBEntities6();
  4.             //model.groups = entities.Groups.ToList();
  5.             model.users = entities.Users.ToList();
  6.             int id = model.subject_id;
  7.             var subj = entities.Subjects
  8.                     .Where(b => b.class_id == model.subject_id)
  9.                     .FirstOrDefault();
  10.             int j = 0;
  11.             model.groups = new List<Group>();
  12.             foreach(var group in entities.Groups)
  13.             {
  14.                 if(group.class_id==model.subject_id)
  15.                 {
  16.                     model.groups.Add(group);
  17.                     j++;
  18.                 }
  19.             }
  20.             if (subj != null)
  21.             {
  22.                 model.subject_name = subj.name;
  23.             }
  24.             if (ModelState.IsValid)
  25.             {
  26.                 DateTime myDate = DateTime.ParseExact(model.deadline+ " "+model.time, "yyyy-MM-dd HH:mm",
  27.                                        System.Globalization.CultureInfo.InvariantCulture);
  28.                 ClassDeclarationsDBEntities6 entities2 = new ClassDeclarationsDBEntities6();
  29.                 int total = entities2.Tasks.Count();
  30.                 string nameAndLocation = "~/UploadedFiles/" + model.file.FileName;
  31.                 model.file.SaveAs(Server.MapPath(nameAndLocation));
  32.                 for (int i=0;i<model.task_names.Count;i++)
  33.                 {
  34.                     ClassDeclarationsDBEntities6 entities3 = new ClassDeclarationsDBEntities6();
  35.                     int maxid;
  36.                     if (total == 0)
  37.                     {
  38.                         maxid = 0;
  39.                     }
  40.                     else {
  41.                         maxid = entities3.Tasks.Max(u => u.task_id);
  42.                     }
  43.  
  44.                     var task = new Models.Task(model.task_names[i], model.subject_id, myDate, model.points[i], maxid + 1, nameAndLocation);
  45.                     entities3.Tasks.Add(task);
  46.                     entities3.SaveChangesAsync();
  47.                 }
  48.                 return RedirectToAction("OperationSuccess", "Account");
  49.             }
  50.             else
  51.             {
  52.                 RedirectToAction("SetHomework", "Account");
  53.                 return View(model);
  54.             }
  55.             return View(model);
  56.  
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement