Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 759
  • 1.1k
  • 51.7k

Save query is not working

Dec 11 2023 12:52 PM

Hello Team,

I have CreatedBy column in sales table which suppose to save userId  in CreatedBy column anytime data save but is not working

public JsonResult SaveInvoiceSale(tblSale sale, List<tblSalesDetail> salesDetail)
        {
            MasterMVCPOS.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage();
            ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities();
            retMessage.IsSuccess = true;           

            foreach (var item in salesDetail)
            {
                sale.tblSalesDetails.Add(new tblSalesDetail { ProductId = item.ProductId, UnitPrice = item.UnitPrice, Quantity = item.Quantity, LineTotal = item.LineTotal });
                var prd = db.tblProductStocks.Where(x => x.ProductId == item.ProductId && x.Quantity > 0).FirstOrDefault();
                prd.Quantity = prd.Quantity - item.Quantity;
                db.Entry(prd).State = EntityState.Modified;
            }
           
            db.tblSales.Add(sale);
            retMessage.Message = "Save successfully!";
            try
            {
                db.SaveChanges();
                retMessage.Data = Convert.ToString(sale.SalesId);
            }
            catch (Exception)
            {
                retMessage.IsSuccess = false;
            }
            return Json(retMessage, JsonRequestBehavior.AllowGet);
        }
 


Answers (3)