public ActionResult Create(TaskViewModel viewModel) { if (ModelState.IsValid) { // kullanıcı sadece yetkisi olan projeler arasından seçim yapabilir if (!Project.GetProjectsByRole().Where(x => x.Id == viewModel.ProjectId).Any()) { return(HttpNotFound()); } var task = new Task(); task.InitFromViewModel(viewModel); task.InitCreateValue(); db.Tasks.Add(task); db.SaveChanges(); TaskAssignedUser.Create(task.Id, Request.Form.GetValues("UserIdMulti")); return(RedirectToAction("Details", "Tasks", new { id = task.Id })); } ViewBag.ProjectId = new SelectList(Project.GetProjectsByRole(), "Id", "Name", viewModel.ProjectId); ViewBag.UserIdMulti = new MultiSelectList(Viola.Models.User.GetUsers(), "Id", "FullName"); return(View(viewModel)); }
public ActionResult Edit(TaskViewModel viewModel) { if (ModelState.IsValid) { // kullanıcı sadece yetkisi olan projeler arasından seçim yapabilir if (!Project.GetProjectsByRole().Where(x => x.Id == viewModel.ProjectId).Any()) { return(HttpNotFound()); } var task = db.Tasks.Single(x => x.Id == viewModel.Id); if (!EntityAuthorization.TaskEdit(task)) { return(HttpNotFound()); } task.InitFromViewModel(viewModel); task.ModifiedUserId = Viola.Models.User.GetCurrentUserId(); task.ModifiedDatetime = DateTime.Now.ToUniversalTime(); db.Entry(task).State = EntityState.Modified; db.SaveChanges(); TaskAssignedUser.Create(task.Id, Request.Form.GetValues("UserIdMulti")); return(RedirectToAction("Details", "Tasks", new { id = task.Id })); } ViewBag.ProjectId = new SelectList(Project.GetProjectsByRole(), "Id", "Name", viewModel.ProjectId); ViewBag.UserIdMulti = new MultiSelectList(Viola.Models.User.GetUsersAssignedToProject(viewModel.ProjectId), "Id", "FullName", TaskAssignedUser.UserIdSelection(viewModel.Id)); return(View(viewModel)); }