public int StoveTx(string cname, string prod, int qty, int cmno) { TxStoveRegulator tx = new TxStoveRegulator(); Customer c = null; c = db.Customers.Where(x => x.CustomerName.Equals(cname)).FirstOrDefault(); if (c != null) { tx.CustomerId = c.CustomerId; tx.CustomerName = c.CustomerName; } else { tx.CustomerId = 0; tx.CustomerName = cname; } tx.TxDate = DateTime.Now; tx.Details = prod; tx.Quentity = qty; var reg = db.Stoves.Where(x => x.type.Equals(prod)).FirstOrDefault(); tx.Price = reg.Price; tx.Amount = Math.Round(qty * tx.Price, 2); var gst = db.GSTRates.Where(x => x.Comodity.Equals("Stove")).FirstOrDefault(); tx.CGST = Math.Round(tx.Amount * gst.CGST / 100, 2); tx.SGST = Math.Round(tx.Amount * gst.SGST / 100, 2); tx.Total = tx.Amount + tx.CGST + tx.SGST; int cmn = 0; if (cmno == 0) { cmn = db.txStoves.Select(x => x.CashMemoNo).Max(m => m) + 1; } else { cmn = cmno; } tx.CashMemoNo = cmn; db.txStoves.Add(tx); db.SaveChanges(); using (LPGContext dbo = new LPGContext()) { var result = dbo.Stoves.Where(x => x.type.Equals(prod)).FirstOrDefault(); result.Quentity = result.Quentity - qty; dbo.SaveChanges(); } return(cmn); }
public string AddStoveTx(string details, int qty) { DistributorUser du = db.DistributorUsers.FirstOrDefault(); TxStoveRegulator ts = new TxStoveRegulator(); ts.CustomerId = du.DistributorCode; ts.CustomerName = du.DistributorName; ts.TxDate = DateTime.Now; ts.Details = details; ts.Quentity = qty; ts.Price = db.Stoves.Where(x => x.type == details).FirstOrDefault().Price; ts.Amount = Math.Round(qty * ts.Price, 2); ts.CGST = 0; ts.SGST = 0; ts.Total = ts.Amount; ts.CashMemoNo = 0; db.txStoves.Add(ts); db.SaveChanges(); return("OK"); }