public async Task <IActionResult> UpdateInvoice(Guid invoiceId, [FromBody] DTOs.Invoice invoiceForUpdate) { var invoiceFromRepo = await _invoiceRepository.GetInvoiceByIdAsync(invoiceId); if (invoiceFromRepo == null) { return(BadRequest()); } var invoiceToUpdate = _mapper.Map(invoiceForUpdate, invoiceFromRepo); var invoiceDetailsForUpdate = invoiceForUpdate.InvoiceDetails.Select(d => new Entities.InvoiceDetail(invoiceId, "preicher", d)).ToList(); try { invoiceToUpdate = _invoiceRepository.UpdateInvoice(invoiceToUpdate); var invDetlsFromRepo = await _invoiceRepository.GetInvoiceDetailsByInvoiceIdAsync(invoiceId); var invDetlsToAdd = invoiceDetailsForUpdate.Where(item => !invDetlsFromRepo.Any(item2 => item2.invoiceDetailId == item.invoiceDetailId)).ToList(); var invDetlsToDelete = invDetlsFromRepo.Where(item => !invoiceDetailsForUpdate.Any(item2 => item2.invoiceDetailId == item.invoiceDetailId)).ToList(); var invDetlsToUpdate = (from indFromUpdate in invoiceForUpdate.InvoiceDetails join indFromRepo in invDetlsFromRepo on indFromUpdate.invoiceDetailId equals indFromRepo.invoiceDetailId where indFromUpdate.InvAmt != indFromRepo.InvAmt select _mapper.Map(indFromUpdate, indFromRepo)).ToList(); invDetlsToDelete.ForEach(invDtl => _invoiceRepository.DeleteInvoiceDetail(invDtl)); invDetlsToAdd.ForEach(invDtl => _invoiceRepository.AddInvoiceDetail(invDtl)); invDetlsToUpdate.ForEach(invDtl => _invoiceRepository.UpdateInvoiceDetail(invDtl)); } catch (Exception ex) { Log.Error(ex.Message); return(StatusCode(500)); } var InvoiceToSend = _mapper.Map <DTOs.Invoice>(invoiceToUpdate); foreach (var itm in invoiceDetailsForUpdate) { InvoiceToSend.InvoiceDetails.Add(new DTOs.InvoiceDetail(itm.budgetCategoryId, itm.budgetId, itm.InvAmt)); //(int budgetCategoryId, int? budgetId, decimal InvAmt) } InvoiceToSend.DocCnt = await _fileUploads.GetUploadCountBySrcIdAsync(invoiceForUpdate.InvoiceId ?? Guid.Empty); return(Ok(InvoiceToSend)); }
public async Task <IActionResult> UpdateEvent(Guid eventId, [FromBody] DTOs.Event eventForUpdate, int DocCnt) { var eventFromRepo = await _armsEventRepository.GetArmsEventIdAsync(eventId); if (eventFromRepo == null) { return(BadRequest()); } eventForUpdate.UserId = "preicher"; _armsEventRepository.UpdateArmsEventType(_mapper.Map(eventForUpdate, eventFromRepo)); var EvtCopy = _mapper.Map <DTOs.Event>(eventFromRepo); EvtCopy.DocCnt = await _fileUploads.GetUploadCountBySrcIdAsync(eventForUpdate.EventId ?? Guid.Empty); return(Ok(EvtCopy)); }
public async Task <IActionResult> UpdateCB(Guid ControllingBoardId, [FromBody] DTOs.ControllingBoard cbForUpdate) { var cbFromRepo = await _controllingBoardRepo.GetArmsCBIdAsync(ControllingBoardId); if (cbFromRepo == null) { return(BadRequest()); } cbForUpdate.UserId = "preicher"; _controllingBoardRepo.UpdateArmsCB(_mapper.Map(cbForUpdate, cbFromRepo)); var copyCB = _mapper.Map <DTOs.ControllingBoard>(cbFromRepo); copyCB.DocCnt = await _fileUploads.GetUploadCountBySrcIdAsync(cbForUpdate.ControllingBoardId ?? Guid.Empty); return(Ok(copyCB)); }
public async Task <IActionResult> UpdateFunding(Guid fundingId, [FromBody] DTOs.Funding fundingForUpdate) { var fundingFromRepo = await _armsFundingRepository.GetArmsFundingIdAsync(fundingId); if (fundingFromRepo == null) { return(BadRequest()); } fundingForUpdate.UserId = "sai"; _armsFundingRepository.UpdateArmsFunding(_mapper.Map(fundingForUpdate, fundingFromRepo)); var result = _mapper.Map <DTOs.Funding>(fundingFromRepo); result.DocCnt = await _fileUploads.GetUploadCountBySrcIdAsync(fundingFromRepo.EncumbranceId); return(Ok(result)); // return Ok(_mapper.Map<DTOs.Funding>(fundingFromRepo)); }