public async Task <ActionResult> Post([FromBody] GarmentFinanceMemorialDetailViewModel viewModel)
        {
            try
            {
                VerifyUser();

                ValidateService.Validate(viewModel);
                GarmentFinanceMemorialDetailModel model = Mapper.Map <GarmentFinanceMemorialDetailModel>(viewModel);
                await Service.CreateAsync(model);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                    .Ok();
                return(Created(String.Concat(Request.Path, "/", 0), Result));
            }
            catch (ServiceValidationException e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GarmentFinanceMemorialDetailViewModel viewModel)
        {
            try
            {
                VerifyUser();

                ValidateService.Validate(viewModel);
                GarmentFinanceMemorialDetailModel model = Mapper.Map <GarmentFinanceMemorialDetailModel>(viewModel);
                await Service.UpdateAsync(id, model);

                return(NoContent());
            }
            catch (ServiceValidationException e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail(e);
                return(BadRequest(Result));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public async Task <IActionResult> GetById([FromRoute] int id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                var model          = await Service.ReadByIdAsync(id);

                GarmentFinanceMemorialDetailViewModel viewModel = Mapper.Map <GarmentFinanceMemorialDetailViewModel>(model);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }

                return(Ok(new
                {
                    apiVersion = ApiVersion,
                    data = viewModel,
                    message = General.OK_MESSAGE,
                    statusCode = General.OK_STATUS_CODE
                }));
            }
            catch (Exception e)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
        public void Should_Success_Validate_Null_Invoice_Data()
        {
            GarmentFinanceMemorialDetailViewModel vm = new GarmentFinanceMemorialDetailViewModel();

            vm.TotalAmount = 100;
            vm.Items       = new List <GarmentFinanceMemorialDetailItemViewModel>
            {
                new GarmentFinanceMemorialDetailItemViewModel()
                {
                    InvoiceId = 0
                }
            };
            vm.OtherItems = new List <GarmentFinanceMemorialDetailOtherItemViewModel>
            {
                new GarmentFinanceMemorialDetailOtherItemViewModel()
                {
                    Account = null,
                    Amount  = 0,
                }
            };
            vm.RupiahItems = new List <GarmentFinanceMemorialDetailRupiahItemViewModel>
            {
                new GarmentFinanceMemorialDetailRupiahItemViewModel()
                {
                    Account = null,
                    Credit  = 0,
                    Debit   = 0,
                }
            };

            Assert.True(vm.Validate(null).Count() > 0);
        }
        public void Should_Success_Validate_Amount_Different()
        {
            GarmentFinanceMemorialDetailViewModel vm = new GarmentFinanceMemorialDetailViewModel();

            vm.Amount = 3;
            vm.Items  = new List <GarmentFinanceMemorialDetailItemViewModel>
            {
                new GarmentFinanceMemorialDetailItemViewModel()
                {
                    Amount = 1,
                }
            };
            vm.OtherItems = new List <GarmentFinanceMemorialDetailOtherItemViewModel>
            {
                new GarmentFinanceMemorialDetailOtherItemViewModel()
                {
                    TypeAmount = "KREDIT",
                    Amount     = 1,
                },
            };

            Assert.True(vm.Validate(null).Count() > 0);
        }
        public void Should_Success_Validate_All_Null_Data()
        {
            GarmentFinanceMemorialDetailViewModel vm = new GarmentFinanceMemorialDetailViewModel();

            Assert.True(vm.Validate(null).Count() > 0);
        }