public async Task AddGoodsReceivedNote(AddGoodsReceivedNote model)
        {
            await RunTaskInTransaction(async() =>
            {
                var note = new Data_Access_Layer.GoodsReceivedNote
                {
                    DocumentId  = model.DocumentId,
                    IssueDate   = model.IssueDate,
                    ReceiveDate = model.ReceiveDate,
                    InvoiceId   = model.InvoiceId
                };

                await GoodsReceivedNoteRepository.Add(note);

                var invoiceEntries = EntryRepository.GetForInvoice(model.InvoiceId);

                foreach (var noteEntry in model.NoteEntry)
                {
                    var productEntity = await ProductRepository.Find(noteEntry.Name);

                    Data_Access_Layer.ProductDetail productDetail = null;

                    var entry = invoiceEntries
                                .FirstOrDefault(ie => ie.Name == noteEntry.Name);

                    if (productEntity == null)
                    {
                        var product = new Data_Access_Layer.Product
                        {
                            Name  = entry.Name,
                            Price = entry.Price,
                            VAT   = entry.VAT
                        };

                        await ProductRepository.Add(product);

                        productDetail = new Data_Access_Layer.ProductDetail
                        {
                            LocationId = noteEntry.Location.Id,
                            ProductId  = product.Id,
                            Count      = entry.Count,
                        };

                        await ProductDetailsRepository.Add(productDetail);

                        continue;
                    }

                    var productDetails = ProductDetailsRepository
                                         .GetForProduct(productEntity.Id)
                                         .FirstOrDefault(pd => pd.LocationId == noteEntry.Location.Id);

                    productDetails.Count += entry.Count;

                    ProductDetailsRepository.Update(productDetails);
                }

                return(string.Empty);
            });
        }
        public override Common.DTO.GoodsReceivedNote Map(Data_Access_Layer.GoodsReceivedNote entity)
        {
            var dto = base.Map(entity);

            Map(entity, dto);
            return(dto);
        }
Example #3
0
 public virtual Common.DTO.GoodsReceivedNote Map(Data_Access_Layer.GoodsReceivedNote entity)
 {
     return(new Common.DTO.GoodsReceivedNote
     {
         DocumentId = entity.DocumentId,
         Invoice = Map(entity.Invoice)
     });
 }
Example #4
0
 public virtual Common.DTO.GoodsReceivedNote Map(Data_Access_Layer.GoodsReceivedNote entity)
 {
     return(new Common.DTO.GoodsReceivedNote
     {
         DocumentId = entity.DocumentId,
         Invoice = Map(entity.Invoice),
         CreatedAt = entity.CreatedAt,
         LastModifiedAt = entity.LastModifiedAt
     });
 }
        public async Task AddGoodsReceivedNote(Controllers.Note.ViewModel.AddGoodsReceivedNote model)
        {
            var transaction = _dbContext.Database.BeginTransaction();

            try
            {
                var note = new Data_Access_Layer.GoodsReceivedNote
                {
                    DocumentId  = model.DocumentId,
                    IssueDate   = model.IssueDate,
                    ReceiveDate = model.ReceiveDate,
                    InvoiceId   = model.InvoiceId
                };

                await GoodsReceivedNoteRepository.Add(note);

                Save();

                var invoiceEntries = await EntryRepository.GetForInvoice(model.InvoiceId);

                foreach (var noteEntry in model.NoteEntry)
                {
                    var productEntity = await ProductRepository.Find(noteEntry.Name);

                    Data_Access_Layer.ProductDetail productDetail = null;

                    var entry = invoiceEntries
                                .FirstOrDefault(ie => ie.Name == noteEntry.Name);

                    if (productEntity == null)
                    {
                        var product = new Data_Access_Layer.Product
                        {
                            Name  = entry.Name,
                            Price = entry.Price,
                            VAT   = entry.VAT
                        };

                        await ProductRepository.Add(product);

                        Save();

                        productDetail = new Data_Access_Layer.ProductDetail
                        {
                            LocationId = noteEntry.Location.Id,
                            ProductId  = product.Id,
                            Count      = entry.Count,
                        };

                        await ProductDetailsRepository.Add(productDetail);

                        Save();

                        continue;
                    }

                    var productDetails = ProductDetailsRepository
                                         .GetForProduct(productEntity.Id)
                                         .FirstOrDefault(pd => pd.LocationId == noteEntry.Location.Id);

                    productDetails.Count += entry.Count;

                    ProductDetailsRepository.Update(productDetails);

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