public ActionResult DeleteConfirmed(int id) { tbl_orderProduct tbl_orderProduct = db.tbl_orderProduct.Find(id); db.tbl_orderProduct.Remove(tbl_orderProduct); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,productId,personId,number,price,description,state")] tbl_orderProduct tbl_orderProduct) { if (ModelState.IsValid) { db.Entry(tbl_orderProduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_orderProduct)); }
public ActionResult Create([Bind(Include = "Id,productId,personId,number,price,description,state")] tbl_orderProduct tbl_orderProduct) { if (ModelState.IsValid) { db.tbl_orderProduct.Add(tbl_orderProduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_orderProduct)); }
// GET: orderDetails/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_orderProduct tbl_orderProduct = db.tbl_orderProduct.Find(id); if (tbl_orderProduct == null) { return(HttpNotFound()); } return(View(tbl_orderProduct)); }
public ActionResult Edit([Bind(Include = "Id,orderId,date,time,anbar1,anbar2,price,state,barcode")] tbl_order tbl_order) { try { int userid = 0; try { userid = int.Parse(Session["userid"].ToString()); } catch (Exception ex) { return(Redirect("~/Home/")); } var currentUser = db.tbl_users.Where(x => x.Id == userid).FirstOrDefault(); var order = db.tbl_order.Where(o => o.orderId == tbl_order.orderId).FirstOrDefault(); if (true) { order.anbar2 = (currentUser.admin && tbl_order.anbar2 != null && tbl_order.anbar2 > 0 ? tbl_order.anbar2 : order.anbar2); order.state = tbl_order.state; if (currentUser.anbardar && !currentUser.admin) { order.state = 3; } db.Entry(order).State = EntityState.Modified; var n = db.SaveChanges(); if (n > 0) { var productIds = Request.Form["productId"]; var productNumbers = Request.Form["productNumber"]; var pNumbers = Request.Form["pNumber"]; var productArray = productIds.Split(','); var numberDarkhstiArray = productNumbers.Split(','); string[] numberArray = null; if (currentUser.admin || currentUser.anbardar) { numberArray = pNumbers.Split(','); } foreach (var item in (db.tbl_orderProduct.Where(x => x.orderId == tbl_order.orderId).ToList())) { db.Entry(item).State = EntityState.Deleted; var y = db.SaveChanges(); } for (int i = 0; i < productArray.Length; i++) { try { var pid = int.Parse(productArray[i]); var tblOProduct = new tbl_orderProduct(); tblOProduct.numberDarkhasti = int.Parse(numberDarkhstiArray[i]); tblOProduct.number = numberArray != null?int.Parse(numberArray[i]) : 0; tblOProduct.description = ""; tblOProduct.orderId = (int)tbl_order.orderId; tblOProduct.personId = currentUser.Id; tblOProduct.price = 0; tblOProduct.productId = pid; tblOProduct.state = currentUser.admin || currentUser.anbardar ? true : false; db.tbl_orderProduct.Add(tblOProduct); var y = db.SaveChanges(); } catch (Exception ex) { } } } ViewBag.currentUser = currentUser; return(Redirect("~/orders/")); //return RedirectToAction("Index"); } } catch (Exception ex) { return(Redirect("~/Home/")); } }
public ActionResult Create([Bind(Include = "Id,orderId,date,time,anbar1,anbar2,price,state,barcode")] tbl_order tbl_order) { int userid = 0; try { userid = int.Parse(Session["userid"].ToString()); } catch (Exception ex) { return(Redirect("~/Home/")); } var currentUser = db.tbl_users.Where(x => x.Id == userid).FirstOrDefault(); if (!currentUser.admin && !currentUser.anbardar) { tbl_order.anbar1 = 1; if (currentUser.anbarId == null || currentUser.anbarId == 0) { return(View()); } tbl_order.anbar2 = currentUser.anbarId; if (string.IsNullOrEmpty(currentUser.pic)) { Session["alert"] = "danger"; Session["message"] = "شما هنوز امضای خود را بارگزاری نکرده اید.برای بارگزاری امضا <a href='/home/profile/" + currentUser.Id + "'>اینجا</a> را کلیک کنید"; return(View()); } } else { return(View()); } var date = Request.Form["date"].ToString(); var time = Request.Form["time"].ToString(); ModelState.Remove("date"); ModelState.Remove("time"); ModelState.Remove("barcode"); ModelState.Remove("orderId"); if (date != "") { tbl_order.date = int.Parse(tools.toEnglishNumber(date).Replace("/", "")); } if (time != "") { tbl_order.time = int.Parse(tools.toEnglishNumber(time).Replace(":", "")); } tbl_order.barcode = date.Replace("/", "") + new Random().Next(10000, 99999).ToString() + time.Replace(":", ""); int order = 1; if (db.tbl_order.ToList().Count > 0) { order = (int)db.tbl_order.OrderByDescending(x => x.orderId).FirstOrDefault().Id; } tbl_order.orderId = db.tbl_order.ToList().Count > 0 ? order + 1 : 1; if (ModelState.IsValid) { db.tbl_order.Add(tbl_order); var n = db.SaveChanges(); if (n > 0) { var orderId = db.tbl_order.Where(x => x.barcode == tbl_order.barcode).First().Id; var productIds = Request.Form["productId"]; var productNumbers = Request.Form["productNumber"]; var productArray = productIds.Split(','); var numberArray = productNumbers.Split(','); for (int i = 0; i < productArray.Length; i++) { try { var pid = int.Parse(productArray[i]); var product = db.tbl_product.Where(x => x.Id == pid).First(); var tblOProduct = new tbl_orderProduct(); tblOProduct.description = ""; tblOProduct.numberDarkhasti = int.Parse(numberArray[i]); tblOProduct.number = 0; tblOProduct.orderId = orderId; tblOProduct.personId = currentUser.Id; tblOProduct.price = 0; tblOProduct.productId = product.Id; tblOProduct.state = false; db.tbl_orderProduct.Add(tblOProduct); var y = db.SaveChanges(); if (y > 0) { var isLimited = db.tbl_productAnbar.Where(x => x.productId == product.Id && x.anbarId == currentUser.anbarId).FirstOrDefault(); if (isLimited == null) { var tpa = new tbl_productAnbar(); tpa.anbarId = (int)currentUser.anbarId; tpa.days = 2; tpa.lastMonthOrder = int.Parse(persianDateClass.getPersianDateTime("mm")); tpa.lastYearOrder = int.Parse(persianDateClass.getPersianDateTime("yyyy")); tpa.maxOrder = product.maxOrder; tpa.productId = product.Id; db.tbl_productAnbar.Add(tpa); db.SaveChanges(); } else { isLimited.lastMonthOrder = int.Parse(persianDateClass.getPersianDateTime("mm")); isLimited.lastYearOrder = int.Parse(persianDateClass.getPersianDateTime("yyyy")); db.Entry(isLimited).State = EntityState.Modified; db.SaveChanges(); } } } catch (Exception ex) { } } } return(RedirectToAction("Index")); } return(View(tbl_order)); }