public ActionResult editnumber(int itemnumber = 0, int id = 0) { var itemselected = db.tbl_purchasekartitemlist.Find(id); int purchasecartid = itemselected.perchasekart_id; entityproducutsreposit entityrep = new entityproducutsreposit(); int max = entityrep.getentityitem(itemselected.product_id); if (itemnumber > max) { string product = itemselected.product_.category.categoryname + " | " + itemselected.product_.name + " کد " + itemselected.product_.codename; return(Json(new { status = "false", productname = product, maxcount = max })); } else { itemselected.number = itemnumber; db.SaveChanges(); editnumberiteminpurchasecart updateoutput = new editnumberiteminpurchasecart(); updateoutput = updatepurchasecart(itemnumber, id, purchasecartid); return(Json(updateoutput)); } }
public editnumberiteminpurchasecart getabstractcartinfo(int cart_id = 0) { editnumberiteminpurchasecart result = new editnumberiteminpurchasecart(); var cartlist = db.tbl_purchasekartitemlist.Where(a => a.perchasekart_id == cart_id); decimal totalprice = 0, totalweight = 0, totalcosttransportation = 0, discount = 0, totalweightsaved = 0; string totalpricestr, totalcosttransportationstr, discountstr, discountcode; var transportationdetails = db.tbl_transportaiondetails.Where(a => a.cartid == cart_id); var transportaioncost = db.tbl_transportationcost.Where(a => a.cart_id == cart_id); foreach (var item in cartlist) { totalprice = totalprice + (decimal)(item.number * item.price); totalweight = totalweight + (decimal)(item.number * (item.product_.weight.HasValue == true ? item.product_.weight.Value : 0)); } totalpricestr = string.Format("{0:#,##0.##}", totalprice) + " ریال"; if (cartlist.Count() > 0) { if (cartlist.FirstOrDefault().perchasekart_.discount_id != null) { discount = Math.Floor(cartlist.FirstOrDefault().perchasekart_.discount_.percentage.Value *totalprice / 100); discountstr = string.Format("{0:#,##0.##}", discount) + " ریال"; discountcode = cartlist.FirstOrDefault().perchasekart_.discount_.discountcode; } else { discount = 0; discountstr = string.Format("{0:#,##0.##}", discount) + " ریال"; discountcode = ""; } if (db.tbl_transportationcost.Where(a => a.cart_id == cart_id).Count() > 0) { totalcosttransportation = db.tbl_transportationcost.Where(a => a.cart_id == cart_id).Sum(a => a.totaltcost.Value); totalcosttransportationstr = string.Format("{0:#,##0.##}", totalcosttransportation) + " ریال"; } else { totalcosttransportation = 0; totalcosttransportationstr = string.Format("{0:#,##0.##}", totalcosttransportation) + " ریال"; } decimal payableprice = 0; string payablepricestr = ""; payableprice = totalprice + totalcosttransportation - discount; payablepricestr = string.Format("{0:#,##0.##}", payableprice) + " ریال"; result.totalprice = totalpricestr; result.totalcosttransportation = totalcosttransportationstr; result.discount = discountstr; result.payableprice = payablepricestr; result.totalweight = totalweight.ToString() + "kg"; return(result); } else { return(new editnumberiteminpurchasecart { totalprice = "", totalcosttransportation = "", discount = "", payableprice = "" }); } }
public editnumberiteminpurchasecart updatepurchasecart(int itemnumber = 0, int purchasecartitemid = 0, int purchasecartid = 0) { var itemselected = db.tbl_purchasekartitemlist.Find(purchasecartitemid); decimal newprice = 0, totalcosttransportation = 0; decimal totalpriceitem = 0; if (itemnumber != 0) { newprice = itemselected.product_.lastcellcost.HasValue == true ? itemselected.product_.lastcellcost.Value : 0; totalpriceitem = newprice * itemnumber; } var cartlist = db.tbl_purchasekartitemlist.Where(a => a.perchasekart_id == purchasecartid).ToList(); decimal totalprice = 0; decimal totalweight = 0; decimal discount = 0; decimal payableprice = 0; string discountstr = "", totalcosttransportationstr = ""; int totalnumber = cartlist.Sum(a => a.number); foreach (var item in cartlist) { totalprice = totalprice + (decimal)(item.number * (item.product_.lastcellcost.HasValue == true ? item.product_.lastcellcost.Value : 0)); totalweight = totalweight + (decimal)(item.number * (item.product_.weight.HasValue == true ? item.product_.weight.Value : 0)); } if (cartlist.Count() > 0) { if (cartlist.FirstOrDefault().perchasekart_.discount_id != null) { discount = Math.Floor(cartlist.FirstOrDefault().perchasekart_.discount_.percentage.Value *totalprice / 100); discountstr = string.Format("{0:#,##0.##}", discount) + " ریال"; } else { discount = 0; discountstr = string.Format("{0:#,##0.##}", discount) + " ریال"; } //int carid = cartlist.FirstOrDefault().perchasekart_id; if (db.tbl_transportationcost.Where(a => a.cart_id == purchasecartid).Count() > 0) { totalcosttransportation = db.tbl_transportationcost.Where(a => a.cart_id == purchasecartid).Sum(a => a.totaltcost.Value); totalcosttransportationstr = string.Format("{0:#,##0.##}", totalcosttransportation) + " ریال"; } else { totalcosttransportation = 0; totalcosttransportationstr = string.Format("{0:#,##0.##}", totalcosttransportation) + " ریال"; } payableprice = totalprice + totalcosttransportation - discount; editnumberiteminpurchasecart editcart = new editnumberiteminpurchasecart(); editcart.newprice = string.Format("{0:#,##0.##}", newprice) + " ریال"; editcart.totalpriceitem = string.Format("{0:#,##0.##}", totalpriceitem) + " ریال"; editcart.totalprice = string.Format("{0:#,##0.##}", totalprice) + " ریال"; editcart.totalweight = string.Format("{0:#,##0.##}", totalweight) + " kg"; editcart.totalnumber = totalnumber.ToString(); editcart.totalcosttransportation = string.Format("{0:#,##0.##}", totalcosttransportation) + " ریال"; editcart.discount = string.Format("{0:#,##0.##}", discount) + " ریال"; editcart.payableprice = string.Format("{0:#,##0.##}", payableprice) + " ریال"; return(editcart); } else { editnumberiteminpurchasecart editcart = new editnumberiteminpurchasecart(); editcart.newprice = string.Format("{0:#,##0.##}", 0) + " ریال"; editcart.totalpriceitem = string.Format("{0:#,##0.##}", 0) + " ریال"; editcart.totalprice = string.Format("{0:#,##0.##}", 0) + " ریال"; editcart.totalweight = string.Format("{0:#,##0.##}", 0) + " kg"; editcart.totalnumber = "0"; editcart.totalcosttransportation = string.Format("{0:#,##0.##}", 0) + " ریال"; editcart.discount = string.Format("{0:#,##0.##}", 0) + " ریال"; editcart.payableprice = string.Format("{0:#,##0.##}", 0) + " ریال"; return(editcart); } }