Esempio n. 1
0
        public async Task <ProjectModel> UpdateProject(Guid projectGuid, UpdateProjectModel model)
        {
            var entity = await _projectData.UpdateProject(projectGuid, model).ConfigureAwait(false);

            var mappedModel = _mapper.Map <ProjectModel>(entity);

            return(mappedModel);
        }
Esempio n. 2
0
 public IHttpActionResult Put(long id, [FromBody] UpdateProjectModel model)
 {
     using (var t = Repository.BeginTransaction())
     {
         var project = ProjectService.UpdateProject(id, model.Name, model.Description);
         t.Commit();
         return(Json(project));
     }
 }
Esempio n. 3
0
        public async Task <IHttpActionResult> UpdateProject([FromUri] Guid projectGuid,
                                                            [FromBody] UpdateProjectModel model)
        {
            try
            {
                var result = await _projectOperations.UpdateProject(projectGuid, model).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (EntityNotFoundException)
            {
                return(BadRequest());
            }
        }
Esempio n. 4
0
        public async Task UpdateProject_ShouldReturnBadRequestIfTheEntityDoesNotExist()
        {
            var projectOperations = new Mock <IProjectOperations>();
            var planOperations    = new Mock <IPlanOperations>();

            var guid  = Guid.NewGuid();
            var model = new UpdateProjectModel();

            projectOperations.Setup(o => o.UpdateProject(guid, model)).Throws <EntityNotFoundException>();

            var controller = new ProjectController(projectOperations.Object, planOperations.Object);

            var result = await controller.UpdateProject(guid, model).ConfigureAwait(false);

            Assert.AreEqual(typeof(BadRequestResult), result.GetType());
        }
Esempio n. 5
0
        public HttpResponseMessage Project(UpdateProjectModel model)
        {
            using (var repo = new ProjectRepository(_projectDataContext))
            {
                var project = repo.Get(model.ProjectId);

                if (project == null)
                {
                    return(Utils.Invalid("Unable to find account to update"));
                }

                project = model.Map();

                var response = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content    = new StringContent(repo.Update(project).ToJson(), Encoding.UTF8, "application/json")
                };
                return(response);
            }
        }
Esempio n. 6
0
        public async Task <Project> UpdateProject(Guid projectGuid, UpdateProjectModel model)
        {
            using (var connection = _connectionHelper.GetConnection())
            {
                var result = await connection.ExecuteAsync(
                    "UPDATE [PROJECT] SET [Name] = @Name, [Description] = @Description, [ModificationTime] = @ModificationTime WHERE [Guid] = @Guid",
                    new { Guid = projectGuid, model.Name, model.Description, ModificationTime = DateTime.Now }
                    ).ConfigureAwait(false);

                if (result == 0)
                {
                    throw new EntityNotFoundException($"No project exists for the guid: {projectGuid}");
                }

                return(await connection
                       .QuerySingleOrDefaultAsync <Project>("SELECT * FROM [PROJECT] WHERE [Guid] = @Guid",
                                                            new { Guid = projectGuid }).ConfigureAwait(false));

                ;
            }
        }
Esempio n. 7
0
        public async Task UpdateProject_ShouldReturnTheUpdatedProject()
        {
            var projectOperations = new Mock <IProjectOperations>();
            var planOperations    = new Mock <IPlanOperations>();

            var expected = new ProjectModel();
            var model    = new UpdateProjectModel();
            var guid     = Guid.NewGuid();

            projectOperations.Setup(o => o.UpdateProject(guid, model)).ReturnsAsync(expected);

            var controller = new ProjectController(projectOperations.Object, planOperations.Object);

            var result =
                await controller.UpdateProject(guid, model).ConfigureAwait(false) as
                OkNegotiatedContentResult <ProjectModel>;

            if (result == null)
            {
                Assert.Fail();
            }

            Assert.AreEqual(expected, result.Content);
        }
Esempio n. 8
0
        public async Task <(bool IsDone, string Message)> UpdateSettingsAsync(Guid userId, UpdateProjectModel model)
        {
            try
            {
                var userAccess = await _securityService.GetUserAccessAsync(userId, model.Id);

                if (!userAccess[UserAction.UPDATE_PROJECT])
                {
                    return(IsDone : false, Message : "You don't have rights");
                }

                var settings = await _context.ProjectSettings.FindAsync(model.Id);

                settings.Preview                     = model.Preview;
                settings.AccessToChangeBoard         = model.AccessToChangeBoard;
                settings.AccessToChangeProject       = model.AccessToChangeProject;
                settings.AccessToChangeTask          = model.AccessToChangeTask;
                settings.UseAdvancedSecuritySettings = model.UseAdvancedSecuritySettings;

                var project = await _context.Projects.FindAsync(model.Id);

                project.Title       = model.Title;
                project.Description = model.Description;

                _context.Projects.Update(project);
                _context.ProjectSettings.Update(settings);
                await _context.SaveChangesAsync();

                return(IsDone : true, Message : "Success");
            }
            catch (Exception e)
            {
                _logger.LogError("ProjectService, UpdateSettingsAsync", e);
            }

            return(IsDone : false, Message : "Something went wrong, try again later");
        }
        public async Task <IActionResult> UpdateSettings([FromBody] UpdateProjectModel model)
        {
            var(IsDone, Message) = await _projectService.UpdateSettingsAsync(this.UserId(), model);

            return(IsDone ? (IActionResult)Ok(Message) : BadRequest(Message));
        }