public override Common.DTO.GoodsDispatchedNote Map(Data_Access_Layer.GoodsDispatchedNote entity)
        {
            var dto = base.Map(entity);

            Map(entity, dto);
            return(dto);
        }
Beispiel #2
0
 public virtual Common.DTO.GoodsDispatchedNote Map(Data_Access_Layer.GoodsDispatchedNote entity)
 {
     return(new Common.DTO.GoodsDispatchedNote
     {
         DocumentId = entity.DocumentId,
         Invoice = Map(entity.Invoice)
     });
 }
Beispiel #3
0
 public virtual Common.DTO.GoodsDispatchedNote Map(Data_Access_Layer.GoodsDispatchedNote entity)
 {
     return(new Common.DTO.GoodsDispatchedNote
     {
         DocumentId = entity.DocumentId,
         Invoice = Map(entity.Invoice),
         CreatedAt = entity.CreatedAt,
         LastModifiedAt = entity.LastModifiedAt
     });
 }
        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 AddGoodsDispatchedNote(Controllers.Note.ViewModel.AddGoodsDispatchedNote model)
        {
            var transaction = _dbContext.Database.BeginTransaction();

            try
            {
                var note = new Data_Access_Layer.GoodsDispatchedNote
                {
                    DocumentId   = model.DocumentId,
                    IssueDate    = model.IssueDate,
                    DispatchDate = model.DispatchDate,
                    InvoiceId    = model.InvoiceId
                };

                await GoodsDispatchedNoteRepository.Add(note);

                Save();

                var invoiceEntries = await 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);

                        Save();
                    }
                    else
                    {
                        ProductDetailsRepository.Update(productDetail);

                        Save();
                    }

                    if (productDetails.Count == 1)
                    {
                        ProductRepository.Remove(productEntity);
                        Save();
                    }
                }

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }