Beispiel #1
0
        public ActionResult EditProject(EditProjectModel editProject)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var icon = GetIcon();

                    var command = new EditProjectsCommand
                    {
                        ProjectId    = editProject.ProjectId,
                        File         = icon,
                        Name         = editProject.Name,
                        ClientName   = editProject.ClientName,
                        Status       = editProject.Status,
                        StartDate    = editProject.StartDate,
                        ProjectOwner = editProject.ProjectOwner,
                        Description  = editProject.Description
                    };

                    var result = mediator.Send(command);

                    if (result == true)
                    {
                        return(RedirectToAction("ProjectManagement", "Admin"));
                    }
                }
                catch (Exception)
                {
                }
            }

            return(RedirectToAction("ProjectManagement"));
        }
Beispiel #2
0
        public async Task <ServiceResult <ProjectModel> > EditProject(EditProjectModel model, string userId)
        {
            var projectRes = await GetEntityById(model.Id);

            if (projectRes.IsError)
            {
                return(ServiceResult <ProjectModel> .NotFound("Project not found"));
            }

            if (!projectRes.Value.Members.Any(m => m.MemberId == userId && m.Role == ProjectRoleEnum.Owner && m.DeletedByUserId == null))
            {
                return(ServiceResult <ProjectModel> .Error("You are cant moderate it"));
            }

            projectRes.Value.InjectFrom(model);
            projectRes.Value.Status = model.Status ?? projectRes.Value.Status;
            projectRes.Value.MarkUpdated(userId);

            _dbContext.Projects.Update(projectRes.Value);
            var count = await _dbContext.SaveChangesAsync();

            return(count != 1
                ? ServiceResult <ProjectModel> .Error("Проект не был обновлен")
                : ServiceResult <ProjectModel> .Ok(GetModelFromEntity(projectRes.Value)));
        }
        public async Task <IActionResult> PutProject(int id, EditProjectModel model)
        {
            var dbProject = await _context.Projects.SingleOrDefaultAsync(p => p.Id == id);

            if (dbProject == null)
            {
                return(BadRequest());
            }

            _mapper.Map(model, dbProject);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectExists(id))
                {
                    return(NotFound());
                }
                throw;
            }
            return(NoContent());
        }
        public ActionResult EditProject(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The project name is null, empty or contains only whitespace which is not allowed.")));
            }

            Project project;

            using (var db = new BuildVersioningDataContext())
            {
                project = db.Projects
                          .SingleOrDefault(p =>
                                           string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                                           );
            }

            if (null == project)
            {
                return(View("Error"));
            }

            var model =
                new EditProjectModel
            {
                BuildNumber = project.BuildNumber,
                Description = project.Description,
                Id          = project.Id,
                Name        = project.Name
            };

            return(View(model));
        }
Beispiel #5
0
        public ActionResult Edit(EditProjectModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect(Url.Project_Edit(model.Id)));
            }
            ProjectObj project;

            if (!model.Id.HasValue)
            {
                project    = ModelConverter.Convert(model);
                project.Id = ProjectLogic.Create(project, CurrentUserName);
                if (project.Id == -1)
                {
                    this.AddError("CreatingProject", "There was an error creating your project. If this continues contact support.");
                    return(Redirect(Url.Project_Create()));
                }
            }
            else
            {
                project = ModelConverter.Convert(model);
                var success = ProjectLogic.Update(project, CurrentUserName);
                if (!success)
                {
                    this.AddError("UpdatingProject", "There was an error updating your project. If this continues contact support.");
                    return(Redirect(Url.Project_Edit(model.Id.Value)));
                }
            }

            return(Redirect(Url.Project_Show(project.Id.Value)));
        }
Beispiel #6
0
        public ActionResult Edit(int?id = null)
        {
            EditProjectModel model = null;

            if (id.HasValue)
            {
                var project = ProjectLogic.Get(id.Value);
                if (project != null)
                {
                    model = ModelConverter.ConvertToEdit(project);
                }
                else
                {
                    this.AddWarning("NoItemFound", "No project was found with that Id. Switching to Create mode.");
                    return(Redirect(Url.Project_Create()));
                }
            }

            if (model == null)
            {
                model      = new EditProjectModel();
                model.Tags = new List <ListItemTagModel>();
            }
            return(View("Edit", model));
        }
        public ActionResult GetEditProjectDialog(String projectId)
        {
            EditProjectModel editProjectModel = new EditProjectModel();

            editProjectModel.Project = _projectService.GetProject(projectId);

            return(PartialView("Partials/EditProject", editProjectModel));
        }
Beispiel #8
0
 internal static ProjectObj Convert(EditProjectModel model)
 {
     return(new ProjectObj
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description
     });
 }
Beispiel #9
0
        public ActionResult ChangeProject(EditProjectModel epm, int id)
        {
            Project updateProj = _projManager.GetProject(id, false);

            updateProj.Title   = epm.Title;
            updateProj.Goal    = epm.Goal;
            updateProj.Visible = epm.Visible;
            updateProj.Status  = epm.Status.ToUpper();


            _projManager.EditProject(updateProj);
            return(RedirectToAction("CollectProject", "Platform", new { id = updateProj.Id }));
        }
Beispiel #10
0
        public ActionResult EditProject(EditProjectModel model)
        {
            if (ModelState.IsValid)
            {
                Project project        = db.Projects.Find(model.ProjectId);
                var     projectMembers = new List <ApplicationUser>();
                projectMembers.AddRange(db.Users.Where(u => model.MemberIds.Contains(u.Id)));

                project.Name             = model.Name;
                project.Description      = model.Description;
                project.ModifiedAt       = DateTime.Now;
                project.TicketTag        = model.TicketTag;
                project.IsActiveProject  = model.IsActiveProject;
                project.ProjectManagerId = model.ProjectManagerId;
                project.ActiveWorkflowId = model.ActiveWorkflowId;
                project.Members.Clear();
                foreach (string uId in model.MemberIds)
                {
                    project.Members.Add(db.Users.Find(uId));
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var projAdmins   = new List <ApplicationUser>();
            var availMembers = new List <ApplicationUser>();

            foreach (ApplicationUser u in db.Users)
            {
                var roles = _permissionsHelper.ListUserRoles(u.Id);
                if (roles.Contains("SuperSolver") || roles.Contains("Solver") || roles.Contains("Reporter"))
                {
                    availMembers.Add(u);
                }
                if (roles.Contains("ProjectAdmin"))
                {
                    projAdmins.Add(u);
                }
            }

            var veiwModel = new EditProjectViewModel()
            {
                SelectedProject       = db.Projects.Find(model.ProjectId),
                ProjectAdministrators = projAdmins,
                AvailableMembers      = availMembers,
                Workflows             = db.ProjectWorkflows.ToList()
            };

            return(View(veiwModel));
        }
Beispiel #11
0
        public async Task <ResultModel> EditProject(EditProjectModel model)
        {
            try
            {
                await projectService.EditProjectAsync(model);

                return(ResultModel.Success("修改成功"));
            }
            catch (AspectInvocationException ex)
            {
                return(ResultModel.Fail(ex.InnerException?.Message));
            }
            catch (MateralConfigCenterException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
Beispiel #12
0
        public async Task EditProjectAsync(EditProjectModel model)
        {
            if (await _projectRepository.ExistedAsync(m => m.Name.Equals(model.Name) && m.ID != model.ID))
            {
                throw new MateralConfigCenterException("名称已存在");
            }
            Project projectFromDb = await _projectRepository.FirstOrDefaultAsync(model.ID);

            if (projectFromDb == null)
            {
                throw new MateralConfigCenterException("项目不存在");
            }
            model.CopyProperties(projectFromDb);
            projectFromDb.UpdateTime = DateTime.Now;
            _protalServerUnitOfWork.RegisterEdit(projectFromDb);
            await _protalServerUnitOfWork.CommitAsync();
        }
Beispiel #13
0
        public void Edit_Post_Create_Bad_ModelState()
        {
            //arrange
            var mockLogic  = new Mock <IProjectLogic>(MockBehavior.Strict);
            var model      = new EditProjectModel();
            var controller = new ProjectController(mockLogic.Object);

            controller = SetupController(controller);
            controller.ModelState.AddModelError("test", "test");

            //act
            var actual      = controller.Edit(model) as RedirectResult;
            var expectedUrl = controller.Url.Project_Create();

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedUrl, actual.Url);
        }
Beispiel #14
0
        public ActionResult Edit(EditProjectModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.IsNew())
                {
                    CreateProjectStatus status = ProjectService.CreateProject(model.Name, model.Description);
                    switch (status)
                    {
                    case CreateProjectStatus.Created:
                        ShowMessage(String.Format((L)"Project '{0}' created.", model.Name));
                        return(RedirectToAction("index"));

                    case CreateProjectStatus.ProjectCountExceeded:
                        ShowMessage((L)"Maximum project count exceeded!", HtmlMessageType.Warning);
                        return(RedirectToAction("index"));

                    case CreateProjectStatus.InvalidName:
                        ModelState.AddModelError("Name", (L)"Invalid project name!");
                        break;
                    }
                }
                else
                {
                    UpdateProjectStatus status = ProjectService.UpdateProject(model.ProjectID, model.Name, model.Description);
                    switch (status)
                    {
                    case UpdateProjectStatus.Updated:
                        ShowMessage(String.Format((L)"Project '{0}' updated.", model.Name));
                        return(RedirectToAction("index"));

                    case UpdateProjectStatus.InvalidName:
                        ModelState.AddModelError("Name", (L)"Invalid project name!");
                        break;

                    case UpdateProjectStatus.NoSuchProject:
                        ShowMessage((L)"No such project!", HtmlMessageType.Warning);
                        return(RedirectToAction("index"));
                    }
                }
            }

            return(View(model));
        }
Beispiel #15
0
        public void Edit_Post_Create_Failure()
        {
            //arrange
            var mockLogic = new Mock <IProjectLogic>(MockBehavior.Strict);

            mockLogic.Setup(m => m.Create(It.IsAny <ProjectObj>(), It.IsAny <string>())).Returns(-1);
            var model      = new EditProjectModel();
            var controller = new ProjectController(mockLogic.Object);

            controller = SetupController(controller);

            //act
            var actual      = controller.Edit(model) as RedirectResult;
            var expectedUrl = controller.Url.Project_Create();

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedUrl, actual.Url);
        }
Beispiel #16
0
        public ActionResult Edit(EditProjectModel model)
        {
            var request = mapper.Value.Map <EditProjectRequest>(model);
            var result  = projectEditor.Value.EditProject(request);

            if (result?.IsSuccess == true)
            {
                return(RedirectToAction(nameof(Index), new { id = result.Project.Code }));
            }

            var project = data.Value.Get(model.Identity);

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

            model.Request  = request;
            model.Response = result;
            TempData.Add(EditProjectKey, model);
            return(RedirectToAction(nameof(Edit), new { id = project.Code }));
        }
        //POST : /api/ProjectBoard/EditProject
        public async Task <Object> EditProject(EditProjectModel model)
        {
            if (model.ProjectTitle != null)
            {
                Project project = _context.Projects.FirstOrDefault(p => p.Id == model.Id);
                if (project != null)
                {
                    project.ProjectTitle = model.ProjectTitle;
                    await _context.SaveChangesAsync();

                    return(Ok());
                }
                else
                {
                    return(BadRequest(new { message = "No Project in database." }));
                }
            }
            else
            {
                return(BadRequest(new { message = "Project title is null." }));
            }
        }
Beispiel #18
0
        public void Edit_Post_Update_Success()
        {
            //arrange
            var id        = 2;
            var mockLogic = new Mock <IProjectLogic>(MockBehavior.Strict);

            mockLogic.Setup(m => m.Update(It.Is <ProjectObj>(p => p.Id == id), It.IsAny <string>())).Returns(true);
            var model = new EditProjectModel()
            {
                Id = id
            };
            var controller = new ProjectController(mockLogic.Object);

            controller = SetupController(controller);

            //act
            var actual      = controller.Edit(model) as RedirectResult;
            var expectedUrl = controller.Url.Project_Show(id);

            //assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedUrl, actual.Url);
        }
Beispiel #19
0
        public ActionResult EditProject(Guid projectId)
        {
            var query = new GetProjectQuery
            {
                ProjectId = projectId
            };

            var project = mediator.Send(query);

            var model = new EditProjectModel()
            {
                ProjectId    = projectId,
                Name         = project.Name,
                ClientName   = project.ClientName,
                Status       = project.Status,
                StartDate    = project.StartDate,
                ProjectOwner = project.ProjectOwner,
                Description  = project.Description,
                IconId       = project.IconId
            };

            return(View(model));
        }
Beispiel #20
0
        public async Task <IActionResult> Edit(EditProjectModel project)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(project));
            }

            string success = await this.service.
                             EditProject(project.Id, project.Name,
                                         (DateTime)project.StartDate,
                                         (DateTime)project.EndDate,
                                         project.Description, (decimal)project.Goal,
                                         project.ImageUrl);

            switch (success)
            {
            case ProjectConst.SuccesfullyEdited:
                this.TempData[ProjectConst.TempDataMessage] = ProjectConst.SuccesfullyEdited;
                return(this.RedirectToAction(nameof(MyProjects)));

            case ProjectConst.StartDateMessage:
                this.TempData[ProjectConst.TempDataMessage] = ProjectConst.StartDateMessage + DateTime.Now.ToShortDateString();
                return(this.View(project));

            case ProjectConst.EndDateMessage:
                this.TempData[ProjectConst.TempDataMessage] = ProjectConst.EndDateMessage;
                return(this.View(project));

            case ProjectConst.Failed:
                this.TempData[ProjectConst.TempDataMessage] = ProjectConst.Failed;
                return(this.View(project));

            default:
                return(this.View(project));
            }
        }
        public ActionResult EditProject(string name, EditProjectModel editProject)
        {
            if (null == editProject)
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The editProject model is null which is not allowed.")));
            }

            var id = editProject.Id;

            if (id < 1)
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The project id is not valid.")));
            }

            var newName = editProject.Name;

            if (string.IsNullOrWhiteSpace(newName))
            {
                return(View("Error", new ErrorInfo("Project", "EditProject", "The new project name is null, empty or contains only whitespace which is not allowed.")));
            }

            var desc = editProject.Description;

            if (string.IsNullOrWhiteSpace(desc))
            {
                desc = null;
            }

            var buildNumber = editProject.BuildNumber;

            if (buildNumber < 0)
            {
                buildNumber = 0;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (name != newName && db.Projects.Any(p => string.Compare(p.Name, newName, StringComparison.OrdinalIgnoreCase) == 0))
                {
                    return(View("Error", new ErrorInfo("Project", "EditProject", "A project with the specified new name already exists.")));
                }

                var project = db.Projects.SingleOrDefault(p => p.Id == id);
                if (null == project)
                {
                    return(View("Error", new ErrorInfo("Project", "EditProject", "The specified project id of the project to be edited does not exist.")));
                }

                project.Name        = newName;
                project.Description = desc;

                if (project.BuildNumber != buildNumber)
                {
                    project.BuildNumber            = buildNumber;
                    project.DateBuildNumberUpdated = DateTime.Now;
                }

                db.SaveChanges();
            }

            return(RedirectToRoute("ViewProject", new { name }));
        }
        public ActionResult UpdateProject(String id, EditProjectModel editProjectModel)
        {
            Boolean updateSuccessful = _projectService.UpdateProject(id, editProjectModel.Project.Name);

            return(RedirectToAction("Index", "Main"));
        }
 public void Put(Guid id, [FromBody] EditProjectModel value)
 {
 }
Beispiel #24
0
 public async Task <IActionResult> Edit([FromBody] EditProjectModel model) =>
 ModelResult(await _projectsService.EditProject(model, CurrentUserId));