public async Task <int> DeleteAsync(int id) { var existingModel = _dbContext.GarmentFinanceBankCashReceiptDetailLocals .Include(d => d.Items) .Include(d => d.OtherItems) .Single(x => x.Id == id && !x.IsDeleted); GarmentFinanceBankCashReceiptDetailLocalModel model = await ReadByIdAsync(id); foreach (var item in model.Items) { EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent, true); } foreach (var otherItem in model.OtherItems) { EntityExtension.FlagForDelete(otherItem, _identityService.Username, UserAgent, true); } EntityExtension.FlagForDelete(model, _identityService.Username, UserAgent, true); var receipts = await _dbContext.GarmentFinanceBankCashReceipts.FirstOrDefaultAsync(a => a.Id == model.BankCashReceiptId); if (receipts != null) { receipts.IsUsed = false; } _dbContext.GarmentFinanceBankCashReceiptDetailLocals.Update(model); return(await _dbContext.SaveChangesAsync()); }
public async Task <int> UpdateAsync(int id, GarmentFinanceBankCashReceiptDetailLocalModel model) { GarmentFinanceBankCashReceiptDetailLocalModel exist = _dbContext.GarmentFinanceBankCashReceiptDetailLocals .Include(d => d.Items) .Include(d => d.OtherItems) .Single(dispo => dispo.Id == id && !dispo.IsDeleted); foreach (var item in exist.Items) { GarmentFinanceBankCashReceiptDetailLocalItemModel itemModel = model.Items.FirstOrDefault(prop => prop.Id.Equals(item.Id)); if (itemModel == null) { EntityExtension.FlagForDelete(item, _identityService.Username, UserAgent, true); } else { item.Amount = itemModel.Amount; EntityExtension.FlagForUpdate(item, _identityService.Username, UserAgent); } } foreach (var newItem in model.Items) { if (newItem.Id == 0) { exist.Items.Add(newItem); EntityExtension.FlagForCreate(newItem, _identityService.Username, UserAgent); } } foreach (var otherItem in exist.OtherItems) { GarmentFinanceBankCashReceiptDetailLocalOtherItemModel itemModel = model.OtherItems.FirstOrDefault(prop => prop.Id.Equals(otherItem.Id)); if (itemModel == null) { EntityExtension.FlagForDelete(otherItem, _identityService.Username, UserAgent, true); } else { otherItem.Amount = itemModel.Amount; otherItem.TypeAmount = itemModel.TypeAmount; EntityExtension.FlagForUpdate(otherItem, _identityService.Username, UserAgent); } } foreach (var newOtherItem in model.OtherItems) { if (newOtherItem.Id == 0) { exist.OtherItems.Add(newOtherItem); EntityExtension.FlagForCreate(newOtherItem, _identityService.Username, UserAgent); } } EntityExtension.FlagForUpdate(exist, _identityService.Username, UserAgent); return(await _dbContext.SaveChangesAsync()); }
public async Task <ActionResult> Post([FromBody] GarmentFinanceBankCashReceiptDetailLocalViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentFinanceBankCashReceiptDetailLocalModel model = Mapper.Map <GarmentFinanceBankCashReceiptDetailLocalModel>(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] GarmentFinanceBankCashReceiptDetailLocalViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); GarmentFinanceBankCashReceiptDetailLocalModel model = Mapper.Map <GarmentFinanceBankCashReceiptDetailLocalModel>(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 <GarmentFinanceBankCashReceiptDetailLocalModel> GetTestData() { GarmentFinanceBankCashReceiptDetailLocalModel model = GetNewData(); await Service.CreateAsync(model); return(await Service.ReadByIdAsync(model.Id)); }
public async Task Should_Error_Get_Local_Sales_Data() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentAsyncMethod()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext))) .Returns(dbContext); var serviceProvider1 = new Mock <IServiceProvider>(); var httpClientService = new Mock <IHttpClientService>(); serviceProviderMock .Setup(x => x.GetService(typeof(IIdentityService))) .Returns(new IdentityService() { Token = "Token", Username = "******", TimezoneOffset = 7 }); HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); message.Content = new StringContent("{\"data\":[{\"salesContractNo\":null,\"localSalesContractId\":0,\"noteNo\":\"21/LBJ/00003\",\"date\":\"2021-08-31T17:00:00+00:00\",\"transactionType\":null,\"buyer\":{\"id\":63,\"code\":\"IJA\",\"name\":\"PT INDORENZA JAYA ABADI\",\"address\":null,\"npwp\":null,\"country\":null,\"nik\":null,\"kaberType\":null},\"tempo\":0,\"expenditureNo\":null,\"dispositionNo\":null,\"useVat\":false,\"remark\":null,\"isUsed\":false,\"paymentType\":null,\"amount\":55000000.0,\"items\":null,\"id\":29,\"active\":false,\"createdUtc\":\"0001 - 01 - 01T00: 00:00\",\"createdBy\":null,\"createdAgent\":null,\"lastModifiedUtc\":\"0001 - 01 - 01T00: 00:00\",\"lastModifiedBy\":null,\"lastModifiedAgent\":null,\"isDeleted\":false,\"deletedUtc\":\"0001 - 01 - 01T00: 00:00\",\"deletedBy\":null,\"deletedAgent\":null},]}"); httpClientService .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/localSalesDebtor")))) .ReturnsAsync(message); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(new HttpClientTestService()); serviceProvider1 .Setup(x => x.GetService(typeof(IIdentityService))) .Returns(new IdentityService() { Token = "Token", Username = "******", TimezoneOffset = 7 }); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(httpClientService.Object); GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); GarmentFinanceMemorialDetailLocalModel modelMemo = _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetNewData(); GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object); GarmentFinanceBankCashReceiptDetailLocalModel cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash).GetTestData(); LocalSalesDebtorReportService service = new LocalSalesDebtorReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod())); var response = await service.GetMonitoring(DateTimeOffset.Now.Month, DateTimeOffset.Now.Year, 7); Assert.Empty(response); }
public async Task Should_Success_Get_All_DataExcel() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentAsyncMethod()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext))) .Returns(dbContext); var serviceProvider1 = new Mock <IServiceProvider>(); var httpClientService = new Mock <IHttpClientService>(); HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK); message.Content = new StringContent("{\"apiVersion\":\"1.0\",\"statusCode\":200,\"message\":\"Ok\",\"data\":[{\"SalesNoteNo\":\"no\",\"amount\":1,\"balanceAmount\":1,\"Date\":\"2018/10/20\",\"truckingDate\":\"2018/10/20\"}],\"info\":{\"count\":1,\"page\":1,\"size\":1,\"total\":2,\"order\":{\"date\":\"desc\"},\"select\":[\"Id\",\"CustomsType\",\"BeacukaiDate\",\"BeacukaiNo\",,\"POSerialNumber\"]}}"); httpClientService .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/finance-reports")))) .ReturnsAsync(message); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(new HttpClientTestService()); serviceProvider1 .Setup(x => x.GetService(typeof(IIdentityService))) .Returns(new IdentityService() { Token = "Token", Username = "******", TimezoneOffset = 7 }); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(httpClientService.Object); GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); GarmentFinanceMemorialDetailLocalModel modelMemo = await _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetTestData(); GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object); GarmentFinanceBankCashReceiptDetailLocalModel cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash, GetCurrentAsyncMethod()).GetTestData(); GarmentFinanceLocalDebtorCardReportService service = new GarmentFinanceLocalDebtorCardReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod())); var response = service.GenerateExcel(DateTimeOffset.Now.Month, DateTimeOffset.Now.Year, modelMemo.Items.First().BuyerCode, 7); Assert.NotNull(response); }
public async Task <int> CreateAsync(GarmentFinanceBankCashReceiptDetailLocalModel model) { EntityExtension.FlagForCreate(model, _identityService.Username, UserAgent); foreach (var item in model.Items) { EntityExtension.FlagForCreate(item, _identityService.Username, UserAgent); } foreach (var otherItem in model.OtherItems) { EntityExtension.FlagForCreate(otherItem, _identityService.Username, UserAgent); } var receipts = await _dbContext.GarmentFinanceBankCashReceipts.FirstOrDefaultAsync(a => a.Id == model.BankCashReceiptId); if (receipts != null) { receipts.IsUsed = true; } _dbContext.GarmentFinanceBankCashReceiptDetailLocals.Add(model); return(await _dbContext.SaveChangesAsync()); }
public async Task Should_Success_Get_Empty_DataExcelSummary() { var serviceProviderMock = GetServiceProvider(); var dbContext = GetDbContext(GetCurrentAsyncMethod()); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext))) .Returns(dbContext); var serviceProvider1 = new Mock <IServiceProvider>(); var httpClientService = new Mock <IHttpClientService>(); serviceProviderMock .Setup(x => x.GetService(typeof(IIdentityService))) .Returns(new IdentityService() { Token = "Token", Username = "******", TimezoneOffset = 7 }); HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.OK); message.Content = new StringContent("{\"data\":[]}"); httpClientService .Setup(x => x.GetAsync(It.Is <string>(s => s.Contains("garment-shipping/local-sales-notes/localSalesDebtor")))) .ReturnsAsync(message); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(new HttpClientTestService()); serviceProvider1 .Setup(x => x.GetService(typeof(IIdentityService))) .Returns(new IdentityService() { Token = "Token", Username = "******", TimezoneOffset = 7 }); serviceProvider1 .Setup(x => x.GetService(typeof(IHttpClientService))) .Returns(httpClientService.Object); GarmentFinanceMemorialDetailLocalService serviceMemo = new GarmentFinanceMemorialDetailLocalService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); GarmentFinanceMemorialDetailLocalModel modelMemo = _dataUtilMemo(serviceMemo, GetCurrentMethod()).GetNewData(); GarmentFinanceBankCashReceiptDetailLocalService serviceBankCash = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object); GarmentFinanceBankCashReceiptDetailLocalModel cashReceiptDetailModel = await _dataUtilBankCash(serviceBankCash).GetTestData(); LocalSalesDebtorReportService service = new LocalSalesDebtorReportService(serviceProvider1.Object, _dbContext(GetCurrentMethod())); var response1 = service.GenerateExcelSummary(1, DateTimeOffset.Now.Year); Assert.NotNull(response1); var response2 = service.GenerateExcelSummary(2, DateTimeOffset.Now.Year); Assert.NotNull(response2); var response3 = service.GenerateExcelSummary(3, DateTimeOffset.Now.Year); Assert.NotNull(response3); var response4 = service.GenerateExcelSummary(4, DateTimeOffset.Now.Year); Assert.NotNull(response4); var response5 = service.GenerateExcelSummary(5, DateTimeOffset.Now.Year); Assert.NotNull(response5); var response6 = service.GenerateExcelSummary(6, DateTimeOffset.Now.Year); Assert.NotNull(response6); var response7 = service.GenerateExcelSummary(7, DateTimeOffset.Now.Year); Assert.NotNull(response7); var response8 = service.GenerateExcelSummary(8, DateTimeOffset.Now.Year); Assert.NotNull(response8); var response9 = service.GenerateExcelSummary(9, DateTimeOffset.Now.Year); Assert.NotNull(response9); var response10 = service.GenerateExcelSummary(10, DateTimeOffset.Now.Year); Assert.NotNull(response10); var response11 = service.GenerateExcelSummary(11, DateTimeOffset.Now.Year); Assert.NotNull(response11); var response12 = service.GenerateExcelSummary(12, DateTimeOffset.Now.Year); Assert.NotNull(response12); }
public async Task Shou0ld_Success_Update_Data() { //Arrange var dbContext = GetDbContext(GetCurrentAsyncMethod()); var serviceProviderMock = GetServiceProvider(); var httpClientService = new Mock <IHttpClientService>(); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(IHttpClientService))) .Returns(httpClientService.Object); serviceProviderMock .Setup(serviceProvider => serviceProvider.GetService(typeof(FinanceDbContext))) .Returns(dbContext); var service = new GarmentFinanceBankCashReceiptDetailLocalService(serviceProviderMock.Object); var model = await _dataUtil(service, GetCurrentAsyncMethod()).GetTestData(); var model2 = await _dataUtil(service, GetCurrentAsyncMethod()).GetTestData(); GarmentFinanceBankCashReceiptDetailLocalModel newModel2 = new GarmentFinanceBankCashReceiptDetailLocalModel(); newModel2.Id = model2.Id; //Act var newModel = await service.ReadByIdAsync(model.Id); var Response1 = await service.UpdateAsync(newModel.Id, newModel); Assert.NotEqual(0, Response1); newModel2.Items = new List <GarmentFinanceBankCashReceiptDetailLocalItemModel> { model2.Items.First() }; newModel2.OtherItems = new List <GarmentFinanceBankCashReceiptDetailLocalOtherItemModel> { model2.OtherItems.First() }; var Response = await service.UpdateAsync(model2.Id, newModel2); Assert.NotEqual(0, Response); GarmentFinanceBankCashReceiptDetailLocalItemModel newItem = new GarmentFinanceBankCashReceiptDetailLocalItemModel { BankCashReceiptDetailLocalId = 1, Amount = 2, }; GarmentFinanceBankCashReceiptDetailLocalOtherItemModel newOtherItem = new GarmentFinanceBankCashReceiptDetailLocalOtherItemModel { BankCashReceiptDetailLocalId = 1, Amount = 2, TypeAmount = "DEBIT" }; newModel2.Items.Add(newItem); newModel2.OtherItems.Add(newOtherItem); var Response3 = await service.UpdateAsync(model2.Id, newModel2); Assert.NotEqual(0, Response); // delete item and other item GarmentFinanceBankCashReceiptDetailLocalModel newModel3 = new GarmentFinanceBankCashReceiptDetailLocalModel(); newModel3.Id = model2.Id; newModel3.Items = new List <GarmentFinanceBankCashReceiptDetailLocalItemModel>(); newModel3.OtherItems = new List <GarmentFinanceBankCashReceiptDetailLocalOtherItemModel>(); var Response4 = await service.UpdateAsync(model2.Id, newModel3); Assert.NotEqual(0, Response4); }