public ActionResult Create(customer_order customer_order) { ApplicationDbContext db = new ApplicationDbContext(); var UserID = User.Identity.GetUserId(); var username = User.Identity.GetUserName(); DateTime checkDate = DateTime.Now.AddHours(3); if (ModelState.IsValid) { if (customer_order.total_qty < 0) { ModelState.AddModelError("", "they can not put a value as yet"); } else { customer_order.invoice_no = customer_order.InvoiceNumber(); customer_order.customer_Id = UserID; customer_order.order_status = null; customer_order.total_balance = customer_order.itermprice(); customer_order.total_paid = customer_order.TotalPrice(); customer_order.order_date = System.DateTime.Now.ToShortDateString(); customer_order.order_month = System.DateTime.Now.Month.ToString(); if (CheckID(username) == true) { var Odl = db.OrderLists.Where(x => x.customerID == username).FirstOrDefault(); Odl.qty = Odl.qty + customer_order.total_qty; Odl.amt = Odl.amt + customer_order.total_paid; Odl.status = "In Progress"; Odl.OrderDate = DateTime.Now.Date; db.Entry(Odl).State = EntityState.Modified; db.SaveChanges(); } else { OrderList od = new OrderList(); od.InvoiceNo = od.GenInvoice(); od.OrderDate = DateTime.Now.Date; od.customerID = User.Identity.GetUserName(); od.qty = customer_order.total_qty; od.amt = customer_order.total_paid; od.status = "In progress"; db.OrderLists.Add(od); db.SaveChanges(); } db.customer_Orders.Add(customer_order); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.ClothsID = new SelectList(db.cloths, "ID", "cloth_Type", customer_order.ClothsID); ViewBag.ServiceID = new SelectList(db.Services, "ID", "service_name", customer_order.ServiceID); return(View(customer_order)); }