private async Task CheckMilestoneIsAddedToDatabase(MilestoneDto milestone, int expectedCount)
        {
            var context             = GetService <TimeTrackingDbContext>();
            var milestoneInDatabase = await context.Milestones.OrderBy(e => e.CreatedAt).LastAsync();

            context.Milestones.Should().HaveCount(expectedCount);
            milestone.Should().BeEquivalentTo(milestoneInDatabase, opt => opt.ExcludingMissingMembers());
        }
예제 #2
0
 private void SetUpMilestone(MilestoneDto milestone, Milestone dbMilestone)
 {
     dbMilestone.Name         = milestone.Name;
     dbMilestone.Objective_ID = milestone.ObjectiveId;
     dbMilestone.StartDate    = milestone.StartDate;
     dbMilestone.Description  = milestone.Description;
     dbMilestone.EndDate      = milestone.EndDate;
 }
예제 #3
0
        public static void Create(MilestoneDto dto)
        {
            using (var db = new MainDBModelContainer())
            {
                var entity = MilestoneMapper.DtoToEntity(dto, db);

                db.MilestoneSet.Add(entity);
                db.SaveChanges();
            }
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var dto = new MilestoneDto()
            {
                EndDate = dateTimePicker1.MinDate,
                Name    = textBox1.Text,
                TaskId  = this.taskid
            };

            MilestoneCreated(dto);
        }
예제 #5
0
 public HttpResponseMessage UpdateMilestone(MilestoneDto milestone)
 {
     try
     {
         _milestoneService.UpdateMilestone(milestone);
         return(Request.CreateResponse(HttpStatusCode.OK, "Successfully updated a miletone!"));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
예제 #6
0
 public static Milestone ToDbEntity(this MilestoneDto milestone)
 {
     return(new Milestone()
     {
         Milestone_ID = milestone.Id,
         Description = milestone.Description,
         EndDate = milestone.EndDate,
         Name = milestone.Name,
         Objective_ID = milestone.ObjectiveId,
         StartDate = milestone.StartDate,
         PlanningStep_ID = milestone.PlanningStepId
     });
 }
예제 #7
0
 public void AddMilestone(MilestoneDto milestone)
 {
     try
     {
         _unitOfWork.MilestoneRepository.Create(milestone.ToDbEntity());
         _unitOfWork.MilestoneRepository.Save();
         _unitOfWork.Commit();
     }
     catch (Exception)
     {
         _unitOfWork.RollBack();
         throw;
     }
 }
예제 #8
0
 public void UpdateMilestone(MilestoneDto milestone)
 {
     try
     {
         var dbMilestone = _unitOfWork.MilestoneRepository.GetById(milestone.Id);
         SetUpMilestone(milestone, dbMilestone);
         _unitOfWork.MilestoneRepository.Save();
         _unitOfWork.Commit();
     }
     catch (Exception)
     {
         _unitOfWork.RollBack();
         throw;
     }
 }
예제 #9
0
        public static MilestoneDto EntityToDto(Milestone entity)
        {
            var dto = new MilestoneDto
            {
                Id      = entity.Id,
                Name    = entity.Name,
                EndDate = entity.EndDate,
            };

            if (entity.Project != null)
            {
                dto.ProjectId = entity.Project.Id;
            }

            return(dto);
        }
예제 #10
0
 public HttpResponseMessage Post(MilestoneDto dto)
 {
     try
     {
         if (dto != null)
         {
             MilestoneRepository.Create(dto);
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Generic error happened."));
     }
 }
        public async Task CreateMilestone_WhenProjectNotFound_ReturnsProjectFound()
        {
            var request = new MilestoneDto()
            {
                State       = State.Closed,
                Description = "description",
                DueDate     = DateTimeOffset.Now,
                ProjectId   = Guid.NewGuid(),
                Title       = "tittle"
            };

            var httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <MilestoneDto> >();

            response.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.ProjectNotFound);
        }
예제 #12
0
        public static Milestone DtoToEntity(MilestoneDto dto, MainDBModelContainer db)
        {
            var entity = new Milestone
            {
                Id      = dto.Id,
                Name    = dto.Name,
                EndDate = dto.EndDate
            };


            if (dto.ProjectId != 0)
            {
                var project = db.ProjectSet.Find(dto.ProjectId);
                entity.Project = project;
            }

            return(entity);
        }
예제 #13
0
        public static void Update(MilestoneDto dto)
        {
            using (var db = new MainDBModelContainer())
            {
                var newData = MilestoneMapper.DtoToEntity(dto, db);
                var oldData = db.MilestoneSet.Find(dto.Id);
                if (oldData != null)
                {
                    oldData.Name    = newData.Name;
                    oldData.EndDate = newData.EndDate;
                    oldData.Project = newData.Project;

                    db.SaveChanges();
                }
                else
                {
                    throw new ElementNotFoundException();
                }
            }
        }
        public async Task CreateMilestone_WhenModelValid_CreatesMilestoneInDbAndReturnsSuccessResponse()
        {
            var milestonesCount = MilestonesDbSet.Get().Count();
            var request         = new MilestoneDto()
            {
                State       = State.Closed,
                Description = "description",
                DueDate     = DateTimeOffset.UtcNow.AddDays(-3050),
                ProjectId   = ProjectsDbSet.Get().First().Id,
                Title       = "tittle"
            };

            var httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <MilestoneDto> >();

            await CheckMilestoneIsAddedToDatabase(response.Data, milestonesCount + 1);

            response.VerifySuccessResponse();
            await ReSeedDatabase();
        }
예제 #15
0
        public async Task <ApiResponse <MilestoneDto> > CreateMileStoneAsync(MilestoneDto dto)
        {
            try
            {
                var projectFound = await _projectRepository.GetByIdAsync(dto.ProjectId);

                if (projectFound == null)
                {
                    _logger.LogWarning("Failed to found project by id {0}", dto.ProjectId);
                    return(new ApiResponse <MilestoneDto>()
                    {
                        StatusCode = 400,
                        IsSuccess = false,
                        ResponseException = new ApiError(ErrorCode.ProjectNotFound, ErrorCode.ProjectNotFound.GetDescription())
                    });
                }
                var entityToAdd = _milestoneMapper.MapToEntity(dto);
                entityToAdd.CreatedByUserId = _userProvider.GetUserId();
                entityToAdd = await _milestoneRepository.AddAsync(entityToAdd);

                if (entityToAdd != null)
                {
                    return(new ApiResponse <MilestoneDto>(_milestoneMapper.MapToModel(entityToAdd)));
                }
                _logger.LogWarning("Failed to create milestone entity {0}", JsonConvert.SerializeObject(dto));
                return(new ApiResponse <MilestoneDto>()
                {
                    StatusCode = 400,
                    IsSuccess = false,
                    ResponseException = new ApiError(ErrorCode.MilestoneCreationFiled, ErrorCode.MilestoneCreationFiled.GetDescription())
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occured while creating milestone {0}", JsonConvert.SerializeObject(dto));
                return(ApiResponse <MilestoneDto> .InternalError());
            }
        }
        public async Task CreateMilestone_WhenNotValidModelPassed_ReturnsValidationError()
        {
            var request = new MilestoneDto()
            {
                State       = State.Closed,
                Description = "description",
                DueDate     = DateTimeOffset.Now,
                Title       = "tittle"
            };
            var httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

            var response = await httpResponse.BodyAs <ApiResponse <MilestoneDto> >();

            response.CheckValidationException(1);

            request = new MilestoneDto()
            {
                State       = State.Closed,
                Description = "description",
                DueDate     = DateTimeOffset.Now
            };
            httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

            response = await httpResponse.BodyAs <ApiResponse <MilestoneDto> >();

            response.CheckValidationException(3);

            request = new MilestoneDto()
            {
                State   = State.Closed,
                DueDate = DateTimeOffset.Now
            };
            httpResponse = await PostAsync(MilestoneControllerRoutes.CreateMilestone, request);

            response = await httpResponse.BodyAs <ApiResponse <MilestoneDto> >();

            response.CheckValidationException(5);
        }
예제 #17
0
 void window_MilestoneCreated(MilestoneDto mile)
 {
     Controllers.MakeApiCallPost("Milestone", new JavaScriptSerializer().Serialize(mile));
     fillMilestones();
 }
 public async Task <ApiResponse <MilestoneDto> > CreateMileStoneAsync([FromBody] MilestoneDto dto)
 {
     return(await _mileStoneService.CreateMileStoneAsync(dto));
 }