//Khoi tao gio hàng theo Masp duoc truyen vao voi Soluong mac dinh la 1 public ShoppingCart(int Masp) { iMasp = Masp; tbl_Product sp = db.tbl_Products.Single(n => n.ID == iMasp); var _Checksp = db.tbl_promotion_details.FirstOrDefault(n => n.Idsp == iMasp); if (_Checksp != null) { tbl_promotion_detail spkm = db.tbl_promotion_details.Single(n => n.Idsp == iMasp); khuyemai = spkm.KhuyenMai.Value; sTensp = sp.TenSP; sAnhbia = sp.UrlHinh; if (khuyemai > 0) { dDongia = double.Parse(spkm.Giakhuyenmai.ToString()); } else { dDongia = double.Parse(sp.GiaHienTai.ToString()); } gift = spkm.Gift; iSoluong = 1; salias = sp.alias; } else { sTensp = sp.TenSP; sAnhbia = sp.UrlHinh; dDongia = double.Parse(sp.GiaHienTai.ToString()); iSoluong = 1; salias = sp.alias; } }
public ActionResult promotionCreate(FormCollection form, String btnAdd, HttpPostedFileBase fileUpload) { if (btnAdd != null) { //Delete checked items string checkedList = form["chk[]"]; if (!String.IsNullOrEmpty(checkedList)) { string[] arrayStringCheckedList = checkedList.Split(new char[] { ',' }); for (int i = 0; i < arrayStringCheckedList.Length; i++) { try { // data.tbl_Products.DeleteOnSubmit(getOneItem(Int32.Parse(arrayStringCheckedList[i]))); data.SubmitChanges(); ViewBag.AlertSuccess = "Xoá thành công!"; } catch (Exception e) { ViewBag.AlertError = "Không xoá được"; } } } } tbl_promotion tic = new tbl_promotion(); var name = form["name"]; var price = form["price"]; var price2 = form["price2"]; var detail = form["detail"]; var sold_amount = form["soldamount"]; tic.alias = DataHelper.GeneralHelper.getInstance().getAliasFromPromotionName(data, name); List <DataHelper.PromotionAddItemModel> list = getProduct(); bool err = false; if (String.IsNullOrEmpty(name)) { err = true; ViewData["Error"] += "Vui lòng nhập tên khuyến mãi!\n"; } tic.Tenkhuyenmai = name; tic.status = true; tic.ngaytao = DateTime.Now; tic.ngaykhuyenmai = Convert.ToDateTime(price); tic.ngayketthuc = Convert.ToDateTime(price2); tic.Noidung = detail; if (form["chkClearImg"] != null) { tic.AnhBia = ""; } else if (fileUpload != null) { var fileName = Path.GetFileName(DateTime.Now.Millisecond + fileUpload.FileName); var path = Path.Combine(Server.MapPath(URLHelper.URL_IMAGE_PATH), fileName); if (!System.IO.File.Exists(path)) { fileUpload.SaveAs(path); } tic.AnhBia = fileName; } if (err == false) { data.tbl_promotions.InsertOnSubmit(tic); data.SubmitChanges(); foreach (var item in list) { tbl_promotion_detail ctkm = new tbl_promotion_detail(); ctkm.Idkm = item.modelid; ctkm.Idsp = item.proid; ctkm.quantity = item.quantity; ctkm.Giaban = (decimal)item.price; ctkm.Giakhuyenmai = (decimal)item.pricepd; ctkm.Gift = item.gift; data.tbl_promotion_details.InsertOnSubmit(ctkm); } return(RedirectToAction("promotionView")); } else { return(View(URLHelper.URL_ADMIN_PROMOTION_M, new Tuple <tbl_promotion, List <tbl_Product> >(tic, getAllItem()))); } }