Exemplo n.º 1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Task task = db.Tasks.Find(id);

            if (task == null)
            {
                return(HttpNotFound());
            }

            if (!EntityAuthorization.TaskEdit(task))
            {
                return(HttpNotFound());
            }

            ViewBag.ProjectId   = new SelectList(Project.GetProjectsByRole(), "Id", "Name", task.ProjectId);
            ViewBag.UserIdMulti = new MultiSelectList(Viola.Models.User.GetUsersAssignedToProject(task.ProjectId), "Id", "FullName", TaskAssignedUser.UserIdSelection(task.Id));
            return(View(Mapper.Map <Task, TaskViewModel>(task)));
        }
Exemplo n.º 2
0
        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));
        }