public static void SaveReq(SRequisition sr) { using (var db = new ADDbContext()) { SRequisition s = new SRequisition(); ReqItem ri = new ReqItem(); if (db.SRequisition.Where(x => x.Id == sr.Id).Any()) { s = db.SRequisition.Where(x => x.Id == sr.Id).FirstOrDefault(); if (s.ListItem != null) { if (s.ListItem.Sum(x => x.Quant) != 0) { foreach (var item in sr.ListItem) { if (s.ListItem.Where(x => x.item.ItemCode == item.item.ItemCode).Any()) { s.ListItem.Where(x => x.item.ItemCode == item.item.ItemCode).FirstOrDefault().Quant = sr.ListItem.Where(x => x.item.ItemCode == item.item.ItemCode).FirstOrDefault().Quant; } else { ri.item = item.item; ri.emp = item.emp; ri.Quant = item.Quant; s.ListItem.Add(ri); } } } else { foreach (var item in sr.ListItem) { item.Quant = 0; } } } } else { s.ListItem = new List <ReqItem>(); foreach (var item in sr.ListItem) { item.emp = db.Employee.Where(x => x.Id == item.emp.Id).FirstOrDefault(); item.item = db.Item.Where(x => x.Id == item.item.Id).FirstOrDefault(); db.ReqItem.Add(item); s.ListItem.Add(item); } db.SaveChanges(); db.SRequisition.Add(s); } db.SaveChanges(); } }
internal static void CreatReqItem(int itemId, int empId, int dif, string v) { ReqItem reitem = new ReqItem(); using (var db = new ADDbContext()) { reitem.item = db.Item.Where(x => x.Id == itemId).FirstOrDefault(); reitem.emp = db.Employee.Where(x => x.Id == empId).FirstOrDefault(); reitem.Status = v; reitem.Quant = dif; db.ReqItem.Add(reitem); db.SaveChanges(); } }
internal static bool SetReqItemCollected(int empId, int itemId) { ReqItem reitem = new ReqItem(); bool status = false; using (var db = new ADDbContext()) { if (db.ReqItem.Where(x => x.item.Id == itemId && x.emp.Id == empId && x.Status.Equals("approved")).Any()) { reitem = db.ReqItem.Where(x => x.item.Id == itemId && x.emp.Id == empId && x.Status.Equals("approved")).FirstOrDefault(); reitem.Status = "collected"; status = true; } db.SaveChanges(); } return(status); }
public JsonResult AddReqItem(int Id, int quant) { SRequisition sr = new SRequisition(); Employee user = EmployeeData.FindByUserName((string)Session["username"]); int id = user.Id; sr = (SRequisition)Session["reqform"]; if (sr == null) { sr = new SRequisition(); sr.ListItem = new List <ReqItem>(); Item p = new Item(); p = ItemData.GetItemById(Id); ReqItem reqitem = new ReqItem(p, user, quant); sr.ListItem.Add(reqitem); } else if (!sr.ListItem.Where(x => x.item.Id == Id).Any()) { Item p = new Item(); p = ItemData.GetItemById(Id); ReqItem reqitem = new ReqItem(p, user, quant); sr.ListItem.Add(reqitem); } else { ReqItem ri = new ReqItem(); ri = sr.ListItem.Where(x => x.item.Id == Id).FirstOrDefault(); ri.Quant = quant; } Session["reqform"] = sr; object new_q = new { quant = sr.ListItem.Sum(x => x.Quant) }; return(Json(new_q, JsonRequestBehavior.AllowGet)); }