Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult PickGroupForHomework(PickGroupForHomeworkViewModel model)
- {
- ClassDeclarationsDBEntities6 entities = new ClassDeclarationsDBEntities6();
- //model.groups = entities.Groups.ToList();
- model.users = entities.Users.ToList();
- int id = model.subject_id;
- var subj = entities.Subjects
- .Where(b => b.class_id == model.subject_id)
- .FirstOrDefault();
- int j = 0;
- model.groups = new List<Group>();
- foreach(var group in entities.Groups)
- {
- if(group.class_id==model.subject_id)
- {
- model.groups.Add(group);
- j++;
- }
- }
- if (subj != null)
- {
- model.subject_name = subj.name;
- }
- if (ModelState.IsValid)
- {
- DateTime myDate = DateTime.ParseExact(model.deadline+ " "+model.time, "yyyy-MM-dd HH:mm",
- System.Globalization.CultureInfo.InvariantCulture);
- ClassDeclarationsDBEntities6 entities2 = new ClassDeclarationsDBEntities6();
- int total = entities2.Tasks.Count();
- string nameAndLocation = "~/UploadedFiles/" + model.file.FileName;
- model.file.SaveAs(Server.MapPath(nameAndLocation));
- for (int i=0;i<model.task_names.Count;i++)
- {
- ClassDeclarationsDBEntities6 entities3 = new ClassDeclarationsDBEntities6();
- int maxid;
- if (total == 0)
- {
- maxid = 0;
- }
- else {
- maxid = entities3.Tasks.Max(u => u.task_id);
- }
- var task = new Models.Task(model.task_names[i], model.subject_id, myDate, model.points[i], maxid + 1, nameAndLocation);
- entities3.Tasks.Add(task);
- entities3.SaveChangesAsync();
- }
- return RedirectToAction("OperationSuccess", "Account");
- }
- else
- {
- RedirectToAction("SetHomework", "Account");
- return View(model);
- }
- return View(model);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement