public IActionResult Edit(int id, EditProjectVM model)
 {
     if (ModelState.IsValid)
     {
         var project = _projects.Read(id);
         project.Name      = model.Name;
         project.StartDate = model.StartDate;
         project.EndDate   = model.EndDate;
         _projects.Update(id, project);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 2
0
        public EditProjectDialog(int projectID)
        {
            InitializeComponent();

            m_OK        = false;
            m_addingNew = false;

            if (projectID == 0)
            {
                m_addingNew = true;
            }

            ProjectVM = new EditProjectVM(projectID);
            ProjectVM.Refresh();

            this.DataContext = ProjectVM;
        }
Esempio n. 3
0
        public void Init()
        {
            ContextMenuVM   = new ContextMenuVM();
            EditProjectVM   = new EditProjectVM(ProjectService);
            DeleteProjectVM = new DeleteProjectVM(ProjectService);
            ContextMenuVM.MenuItems.Add(new ContextMenuItemVM("Edit", () =>
            {
                State = ProjectState.Edit;
                EditProjectVM.IsVisible = true;
                ContextMenuVM.IsOpen    = false;
            }));
            ContextMenuVM.MenuItems.Add(new ContextMenuItemVM("Delete", () =>
            {
                State = ProjectState.Delete;
                //TODO: Delete prompt
                DeleteProjectVM.IsVisible = true;
                ContextMenuVM.IsOpen      = false;
            }));

            DeleteProjectVM.OnDelete += DeleteProjectVM_OnDelete;
        }
        public async Task <IActionResult> Edit(int?id)
        {
            // check that project exists
            if (id == null)
            {
                return(NotFound());
            }
            var project = await _context.Project.FindAsync(id);

            if (project == null)
            {
                return(NotFound());
            }

            // Authorize user to edit this project
            if (!User.IsInRole("Administrator"))
            {
                var userId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                if (userId != project.ProjectOwnerId)
                {
                    return(Unauthorized());
                }
            }

            // fix any null data
            if (project.ProjectOwnerUserName == null)
            {
                project.ProjectOwnerUserName = "******";
            }
            if (project.ProjectOwnerId == null)
            {
                project.ProjectOwnerId = "unassigned";
            }

            /*
             * // get current project owner's username
             * if (project.ProjectOwnerUserName == null)
             * {
             *      string currentProjectOwnerUserName = "";
             *      try
             *      {
             *              currentProjectOwnerUserName = _context.Users
             *              .FindAsync(project.ProjectOwnerId)
             *              .Result.UserName;
             *      }
             *      catch
             *      {
             *              currentProjectOwnerUserName = "******";
             *      }
             * }
             */

            // populate a list of all possible alternative Project Managers' usernames, for the dropdown box
            List <string> possibleProjectOwnerUserNames = new List <string>();
            var           PMs = await _userManager.GetUsersInRoleAsync("Project Manager");

            var admins = await _userManager.GetUsersInRoleAsync("Administrator");

            PMs.ToList().ForEach(u => possibleProjectOwnerUserNames.Add(u.UserName));
            admins.ToList().ForEach(u => possibleProjectOwnerUserNames.Add(u.UserName));
            possibleProjectOwnerUserNames.Remove(project.ProjectOwnerUserName);

            EditProjectVM vm = new EditProjectVM
            {
                Project = project,
                PossibleProjectOwnerUserNames = possibleProjectOwnerUserNames
            };

            return(View(vm));
        }