예제 #1
0
        public IHttpActionResult Update([FromBody] ProjectDTO project)
        {
            ThrowIfUserHasNoRole(updateRole);
            if (project == null)
            {
                throw new KairosException("Missing model parameter");
            }

            if (project.Project_PK == 0)
            {
                throw new KairosException("Put method is not allowed because the requested primary key is '0' (zero) .");
            }

            using (var projectUpdateHandler = new ProjectUpdateHandler(Db, ActiveUser, new ProjectValidator(), new ProjectFactory(Db, ActiveUser), new ProjectQuery(Db), AccessControl))
            {
                using (var transaction = new TransactionScope())
                {
                    var saveResult = projectUpdateHandler.Save(project, DateTime.Now);
                    transaction.Complete();
                    if (saveResult.Success)
                    {
                        return(Ok(new SuccessResponse(saveResult.Model, saveResult.Message)));
                    }
                    return(Ok(new ErrorResponse(ServiceStatusCode.ValidationError, saveResult.ValidationResult, saveResult.Message)));
                }
            }
        }
 public ProjectReservationUpdateHandlerTest()
 {
     _fakeRepository = new Mock <IProjectRepository>();
     _mapper         = new Mock <IMapper>();
     _handler        = new ProjectUpdateHandler(_fakeRepository.Object, _mapper.Object);
 }