示例#1
0
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiSalesReasonRequestModel model)
 {
     this.ModifiedDateRules();
     this.NameRules();
     this.ReasonTypeRules();
     return(await this.ValidateAsync(model, id));
 }
        private async Task <ApiSalesReasonResponseModel> CreateRecord()
        {
            var model = new ApiSalesReasonRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B");
            CreateResponse <ApiSalesReasonResponseModel> result = await this.Client.SalesReasonCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLSalesReasonMapper();
            ApiSalesReasonRequestModel model = new ApiSalesReasonRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A");
            BOSalesReason response = mapper.MapModelToBO(1, model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ReasonType.Should().Be("A");
        }
示例#4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSalesReasonModelMapper();
            var model  = new ApiSalesReasonResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A");
            ApiSalesReasonRequestModel response = mapper.MapResponseToRequest(model);

            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ReasonType.Should().Be("A");
        }
示例#5
0
        public virtual async Task <IActionResult> Create([FromBody] ApiSalesReasonRequestModel model)
        {
            CreateResponse <ApiSalesReasonResponseModel> result = await this.SalesReasonService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/SalesReasons/{result.Record.SalesReasonID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual BOSalesReason MapModelToBO(
            int salesReasonID,
            ApiSalesReasonRequestModel model
            )
        {
            BOSalesReason boSalesReason = new BOSalesReason();

            boSalesReason.SetProperties(
                salesReasonID,
                model.ModifiedDate,
                model.Name,
                model.ReasonType);
            return(boSalesReason);
        }
示例#7
0
        public virtual async Task <CreateResponse <ApiSalesReasonResponseModel> > Create(
            ApiSalesReasonRequestModel model)
        {
            CreateResponse <ApiSalesReasonResponseModel> response = new CreateResponse <ApiSalesReasonResponseModel>(await this.salesReasonModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.bolSalesReasonMapper.MapModelToBO(default(int), model);
                var record = await this.salesReasonRepository.Create(this.dalSalesReasonMapper.MapBOToEF(bo));

                response.SetRecord(this.bolSalesReasonMapper.MapBOToModel(this.dalSalesReasonMapper.MapEFToBO(record)));
            }

            return(response);
        }
示例#8
0
        public void CreatePatch()
        {
            var mapper = new ApiSalesReasonModelMapper();
            var model  = new ApiSalesReasonRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A");

            JsonPatchDocument <ApiSalesReasonRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiSalesReasonRequestModel();

            patch.ApplyTo(response);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ReasonType.Should().Be("A");
        }
示例#9
0
        private async Task <ApiSalesReasonRequestModel> PatchModel(int id, JsonPatchDocument <ApiSalesReasonRequestModel> patch)
        {
            var record = await this.SalesReasonService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiSalesReasonRequestModel request = this.SalesReasonModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
示例#10
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISalesReasonRepository>();
            var model = new ApiSalesReasonRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <SalesReason>())).Returns(Task.FromResult(new SalesReason()));
            var service = new SalesReasonService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SalesReasonModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSalesReasonMapperMock,
                                                 mock.DALMapperMockFactory.DALSalesReasonMapperMock);

            CreateResponse <ApiSalesReasonResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SalesReasonModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSalesReasonRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <SalesReason>()));
        }
示例#11
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ISalesReasonRepository>();
            var model = new ApiSalesReasonRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new SalesReasonService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.SalesReasonModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLSalesReasonMapperMock,
                                                 mock.DALMapperMockFactory.DALSalesReasonMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.SalesReasonModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
示例#12
0
        public virtual async Task <UpdateResponse <ApiSalesReasonResponseModel> > Update(
            int salesReasonID,
            ApiSalesReasonRequestModel model)
        {
            var validationResult = await this.salesReasonModelValidator.ValidateUpdateAsync(salesReasonID, model);

            if (validationResult.IsValid)
            {
                var bo = this.bolSalesReasonMapper.MapModelToBO(salesReasonID, model);
                await this.salesReasonRepository.Update(this.dalSalesReasonMapper.MapBOToEF(bo));

                var record = await this.salesReasonRepository.Get(salesReasonID);

                return(new UpdateResponse <ApiSalesReasonResponseModel>(this.bolSalesReasonMapper.MapBOToModel(this.dalSalesReasonMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiSalesReasonResponseModel>(validationResult));
            }
        }
示例#13
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiSalesReasonRequestModel model)
        {
            ApiSalesReasonRequestModel request = await this.PatchModel(id, this.SalesReasonModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiSalesReasonResponseModel> result = await this.SalesReasonService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
示例#14
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSalesReasonRequestModel> patch)
        {
            ApiSalesReasonResponseModel record = await this.SalesReasonService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiSalesReasonRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiSalesReasonResponseModel> result = await this.SalesReasonService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }