public static bool EffortCreate(EffortViewModel viewModel) { bool ret = true; // kullanıcı eforunu sadece yetkisi olduğu tasklara girebilir if (!Task.GetTasksByRole().Where(x => x.Id == viewModel.TaskId).Any()) { ret = false; } // kullanıcılar sadece yetkileri olduğu kişilerin eforlarını düzenleyebilir // admin: herkesi // user: sadece kendisini if (!Viola.Models.User.GetUsersForEffort().Where(x => x.Id == viewModel.UserId).Any()) { ret = false; } return(ret); }
public ActionResult Create(EffortViewModel viewModel) { if (ModelState.IsValid) { if (!EntityAuthorization.EffortCreate(viewModel)) { return(HttpNotFound()); } var effort = new Effort(); effort.InitFromViewModel(viewModel); effort.InitCreateValue(); db.Efforts.Add(effort); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(Viola.Models.User.GetUsersForEffort(), "Id", "FullName", viewModel.UserId); ViewBag.TaskId = new SelectList(Task.GetTasksByRole(), "Id", "Name", viewModel.TaskId); return(View(viewModel)); }
public ActionResult Edit(EffortViewModel viewModel) { if (ModelState.IsValid) { var effort = db.Efforts.Single(x => x.Id == viewModel.Id); if (!EntityAuthorization.EffortEdit(effort)) { return(HttpNotFound()); } effort.InitFromViewModel(viewModel); effort.ModifiedUserId = Viola.Models.User.GetCurrentUserId(); effort.ModifiedDatetime = DateTime.Now.ToUniversalTime(); db.Entry(effort).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(Viola.Models.User.GetUsersForEffort(), "Id", "FullName", viewModel.UserId); ViewBag.TaskId = new SelectList(Task.GetTasksByRole(), "Id", "Name", viewModel.TaskId); return(View(viewModel)); }