Esempio n. 1
0
        public ValidateInvoiceViewModel GetSupplierDelOrder(string supplierId)
        {
            var query = (from x in context.DeliveryOrder
                         where x.SupplierId == supplierId && x.Status != "BILLED"
                         orderby x.DelOrderId
                         select new DelOrderDetailsViewModel
            {
                DelOrderNo = x.DelOrderNo,
                Date = x.Date,
            }).ToList();
            ValidateInvoiceViewModel model = new ValidateInvoiceViewModel
            {
                DelOrderDetails = query
            };

            return(model);
        }
Esempio n. 2
0
        public bool CreateInvoice(ValidateInvoiceViewModel model)
        {
            bool     isSuccess;
            string   invoiceNo   = model.InvoiceNo;
            DateTime invoiceDate = DateTime.Now;
            string   supplierId  = model.SupplierId;
            decimal  invoiceAmt  = model.InvoiceAmt;

            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    foreach (var item in model.DelOrderDetails)
                    {
                        if (item.isSelected)
                        {
                            string invoiceId  = GenerateInvoiceId();
                            string delOrderId = GetDelOrderId(item.DelOrderNo);
                            var    query      = context.DeliveryOrder.FirstOrDefault(x => x.DelOrderId == delOrderId);
                            query.Status = "BILLED";
                            Invoice newInvoice = new Invoice();
                            newInvoice.InvoiceId     = invoiceId;
                            newInvoice.InvoiceNo     = invoiceNo;
                            newInvoice.SupplierId    = supplierId;
                            newInvoice.InvoiceAmount = invoiceAmt;
                            newInvoice.InvoiceDate   = invoiceDate;
                            newInvoice.DelOrderId    = delOrderId;
                            context.Invoice.Add(newInvoice);
                            context.SaveChanges();
                        }
                    }
                    dbContextTransaction.Commit();
                    isSuccess = true;
                }
                catch (Exception)
                {
                    dbContextTransaction.Rollback();
                    isSuccess = false;
                }
            }

            return(isSuccess);
        }
Esempio n. 3
0
        public ActionResult Validate(ValidateInvoiceViewModel model)
        {
            bool isSuccess = pService.CreateInvoice(model);

            return(RedirectToAction("Index", isSuccess ? new { id = 1 } : new { id = 2 }));
        }