public async Task <HttpResult <bool> > AddGoodsDispatchedNote(GoodsDispatchedNote note, CancellationToken token = default(CancellationToken)) { var result = new HttpResult <bool>(); var model = new AddGoodsDispatchedNote() { DocumentId = note.DocumentId, InvoiceId = note.InvoiceId, IssueDate = note.IssueDate, DispatchDate = note.DispatchDate, NoteEntry = note .NoteEntry .Select(ne => new WebApiServer.Controllers.Note.ViewModel.NoteEntry { Location = new Common.DTO.Location { Id = ne.Location.Id, Name = ne.Location.Name }, Name = ne.Name }) .ToList() }; await _unitOfWork.AddGoodsDispatchedNote(model); return(result); }
public async Task AddGoodsDispatchedNote(AddGoodsDispatchedNote model) { await RunTaskInTransaction(async() => { var note = new Data_Access_Layer.GoodsDispatchedNote { DocumentId = model.DocumentId, IssueDate = model.IssueDate, DispatchDate = model.DispatchDate, InvoiceId = model.InvoiceId }; await GoodsDispatchedNoteRepository.Add(note); var invoiceEntries = EntryRepository.GetForInvoice(model.InvoiceId); foreach (var noteEntry in model.NoteEntry) { var productEntity = await ProductRepository.Find(noteEntry.Name); var entry = invoiceEntries .FirstOrDefault(ie => ie.Name == noteEntry.Name); var productDetails = ProductDetailsRepository .GetForProduct(productEntity.Id); var productDetail = productDetails .FirstOrDefault(pd => pd.Location.Id == noteEntry.Location.Id); productDetail.Count -= entry.Count; if (productDetail.Count <= 0) { ProductDetailsRepository.Remove(productDetail); } else { ProductDetailsRepository.Update(productDetail); } if (productDetails.Count == 1) { ProductRepository.Remove(productEntity); } } return(string.Empty); }); }
public async Task <IActionResult> AddGoodsDispatchedNote([FromBody] AddGoodsDispatchedNote model) { await _unitOfWork.AddGoodsDispatchedNote(model); return(Ok()); }