public ActionResult Create(Shop shop) { if (Session["swi"] == null) { return(RedirectToAction("Index", "Home")); } if (Session["swi"] != null && Session["isadmin"] == "yes") { return(RedirectToAction("Index", "Customers")); } if (ModelState.IsValid) { if (shop != null) { Shop x = new Shop(); x.Delevery = shop.Delevery; x.Phone = shop.Phone; x.About = shop.About; x.Location = ""; Cust_ShopDBContext csss = new Cust_ShopDBContext(); int id = (int)Session["swi"]; int count = (from a in csss.cust_shop where a.Cust_Id == id select a).Count(); CustomersDBContext cst = new CustomersDBContext(); var qq2 = from b in cst.customer where id == b.Cust_Id select b; int accountcount = 0; foreach (var item in qq2) { accountcount = item.Account_count; } if (count < accountcount) { if (shop.About == null || shop.Delevery == null) { return(RedirectToAction("Index")); } db.shop.Add(x); db.SaveChanges(); Cust_ShopDBContext cs = new Cust_ShopDBContext(); Cust_Shop cos = new Cust_Shop(); cos.Cust_Id = id; cos.S_Id = x.S_Id; cs.cust_shop.Add(cos); cs.SaveChanges(); return(RedirectToAction("mapv")); } TempData["counters"] = "Sorry You already have the limit shops "; return(RedirectToAction("Index", "Customers")); } else { Shop s = new Shop(); return(View(s)); } } return(View(shop)); }
public ActionResult DeleteConfirmed(int id) { if (Session["swi"] == null) { return(RedirectToAction("Index", "Home")); } if (Session["swi"] != null && Session["isadmin"] == "yes") { return(RedirectToAction("Index", "Customers")); } Cust_ShopDBContext csd = new Cust_ShopDBContext(); Cust_Shop csop = new Cust_Shop(); var qwee = from o in csd.cust_shop where o.S_Id == id select o; int opq = 0; foreach (var item in qwee) { opq = item.Cust_Id; csop = item; } int swint = (int)Session["swi"]; if (opq != swint) { return(RedirectToAction("Index", "Customers")); } csd.cust_shop.Remove(csop); csd.SaveChanges(); var s = from a in sdb.shopit where a.S_Id == id select a; foreach (var q in s) { Shop_item x = new Shop_item(); x = q; sdb.shopit.Remove(q); var result = from t in itdb.item where t.T_Id == x.T_Id orderby t.T_Id descending select t; Items ti = result.First(); itdb.item.Remove(ti); var q2 = from a in itp.item_val where a.T_Id == x.T_Id select a; foreach (var item in q2) { itp.item_val.Remove(item); } var q3 = from a in ratdb.itrat where a.Id == ti.T_Id select a; foreach (var item in q3) { ratdb.itrat.Remove(item); } } Shop shop = db.shop.Find(id); db.shop.Remove(shop); /*itdp.SaveChanges(); * shopit.SaveChanges(); * db.SaveChanges(); * ratdb.SaveChanges();*/ itp.SaveChanges(); sdb.SaveChanges(); itdb.SaveChanges(); db.SaveChanges(); ratdb.SaveChanges(); return(RedirectToAction("Index")); }
public void rm(int customer_id) { RRDBContext ratedb = new RRDBContext(); ItemvalueDBContext itemvaluedb = new ItemvalueDBContext(); ShopItemDBContext shopitemdb = new ShopItemDBContext(); ItemDBContext itemdb = new ItemDBContext(); Cust_ShopDBContext custshopdb = new Cust_ShopDBContext(); shopDBContext shopdb = new shopDBContext(); //Cs_SuDBContext cssudb = new Cs_SuDBContext(); //CustomersDBContext customerdb = new CustomersDBContext(); int shop_id; var q1 = from a1 in custshopdb.cust_shop where a1.Cust_Id == customer_id select a1; foreach (var item1 in q1.ToList()) { shop_id = item1.S_Id; var q2 = from a2 in shopitemdb.shopit where a2.S_Id == shop_id select a2; int item_id; Shop_item si; foreach (var item2 in q2.ToList()) { item_id = item2.T_Id; var q3 = from a3 in itemvaluedb.item_val where item_id == a3.T_Id select a3; Item_value iv; foreach (var item3 in q3.ToList()) { iv = item3; itemvaluedb.item_val.Remove(iv); itemvaluedb.SaveChanges(); } si = item2; shopitemdb.shopit.Remove(si); shopitemdb.SaveChanges(); var q4 = from a4 in itemdb.item where a4.T_Id == item_id select a4; Items it; foreach (var item4 in q4.ToList()) { it = item4; itemdb.item.Remove(it); itemdb.SaveChanges(); Item_rate r = ratedb.itrat.Find(it.T_Id); ratedb.itrat.Remove(r); ratedb.SaveChanges(); } } Cust_Shop cs = item1; custshopdb.cust_shop.Remove(cs); custshopdb.SaveChanges(); Shop s; var q5 = from a5 in shopdb.shop where a5.S_Id == shop_id select a5; foreach (var item5 in q5.ToList()) { s = item5; shopdb.shop.Remove(s); shopdb.SaveChanges(); } } var q6 = from a6 in db5.cs_su where a6.Customer == customer_id select a6; Cs_Su cssu; foreach (var item6 in q6.ToList()) { cssu = item6; db5.cs_su.Remove(cssu); db5.SaveChanges(); } Customers custome = db.customer.Find(customer_id); db.customer.Remove(custome); db.SaveChanges(); }