public async Task <int> CreateFromUnitReceiptNoteAsync(CreditorAccountUnitReceiptNotePostedViewModel viewModel) { CreditorAccountModel model = new CreditorAccountModel() { UnitReceiptNotePPN = viewModel.PPN, FinalBalance = viewModel.DPP + viewModel.PPN, InvoiceNo = viewModel.InvoiceNo, SupplierCode = viewModel.SupplierCode, SupplierName = viewModel.SupplierName, SupplierIsImport = viewModel.SupplierIsImport, UnitReceiptMutation = viewModel.DPP + viewModel.PPN, UnitReceiptNoteDate = viewModel.Date, UnitReceiptNoteDPP = viewModel.DPP, UnitReceiptNoteNo = viewModel.Code, CurrencyCode = viewModel.Currency, DPPCurrency = viewModel.DPPCurrency, CurrencyRate = viewModel.CurrencyRate, PaymentDuration = viewModel.PaymentDuration, Products = viewModel.Products, DivisionId = viewModel.DivisionId, DivisionCode = viewModel.DivisionCode, DivisionName = viewModel.DivisionName, UnitId = viewModel.UnitId, UnitCode = viewModel.UnitCode, UnitName = viewModel.UnitName }; return(await CreateAsync(model)); }
public async Task <int> UpdateFromUnitReceiptNoteAsync(CreditorAccountUnitReceiptNotePostedViewModel viewModel) { CreditorAccountModel data = await DbSet.FirstOrDefaultAsync(x => x.UnitReceiptNoteNo == viewModel.Code); if (data == null) { throw new NotFoundException(); } data.UnitReceiptNotePPN = (viewModel.UseIncomeTax ? (decimal)0.1 * viewModel.DPP : 0); data.UnitReceiptNoteNo = viewModel.Code; data.UnitReceiptNoteDPP = viewModel.DPP; data.UnitReceiptNoteDate = viewModel.Date; data.UnitReceiptMutation = viewModel.DPP + (viewModel.UseIncomeTax ? (decimal)0.1 * viewModel.DPP : 0); data.FinalBalance = data.UnitReceiptMutation + data.BankExpenditureNoteMutation; data.DivisionId = viewModel.DivisionId; data.DivisionCode = viewModel.DivisionCode; data.DivisionName = viewModel.DivisionName; data.UnitId = viewModel.UnitId; data.UnitCode = viewModel.UnitCode; data.UnitName = viewModel.UnitName; UpdateModel(data.Id, data); return(await DbContext.SaveChangesAsync()); }
public async Task <IActionResult> UnitReceiptNoteGet([FromQuery] string supplierCode, [FromQuery] string code, [FromQuery] string invoiceNo) { try { CreditorAccountUnitReceiptNotePostedViewModel vm = await Service.GetByUnitReceiptNote(supplierCode, code, invoiceNo); if (vm == null) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE) .Fail(); return(NotFound(Result)); } else { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.OK_STATUS_CODE, General.OK_MESSAGE) .Ok(Mapper, vm); return(Ok(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> UnitReceiptNotePutDelete([FromBody] CreditorAccountUnitReceiptNotePostedViewModel viewModel) { try { VerifyUser(); await Service.DeleteFromUnitReceiptNoteAsync(viewModel); return(NoContent()); } catch (NotFoundException) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(); 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 <ActionResult> UnitReceiptNotePost([FromBody] CreditorAccountUnitReceiptNotePostedViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); await Service.CreateFromUnitReceiptNoteAsync(viewModel); 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 Should_Success_DeleteBy_UnitReceiptNote_Model_NotFound() { CreditorAccountService service = new CreditorAccountService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); var newData = new CreditorAccountUnitReceiptNotePostedViewModel(); var deleteResponse = await service.DeleteFromUnitReceiptNoteAsync(newData); Assert.Equal(0, deleteResponse); }
public async Task <int> DeleteFromUnitReceiptNoteAsync(CreditorAccountUnitReceiptNotePostedViewModel viewModel) { CreditorAccountModel model = await DbSet.FirstOrDefaultAsync(x => x.UnitReceiptNoteNo == viewModel.Code); if (model != null) { return(await DeleteAsync(model.Id)); } else { return(0); } }
public async Task Should_Fail_Put_UnitReceiptNote() { CreditorAccountService service = new CreditorAccountService(GetServiceProvider().Object, _dbContext(GetCurrentMethod())); CreditorAccountUnitReceiptNotePostedViewModel newData = new CreditorAccountUnitReceiptNotePostedViewModel(); await Assert.ThrowsAnyAsync <NotFoundException>(() => service.UpdateFromUnitReceiptNoteAsync(newData)); }