public ActionResult Add(string key, string code) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); var model = new Shop_Product_Detail(); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } UpdateModel(model); var CodeSku = Request["CodeSku"]; model.IsDelete = false; var lstPicture = Request["Value_DefaultImages"]; if (!string.IsNullOrEmpty(lstPicture)) { var lstInt = FDIUtils.StringToListInt(lstPicture); model.PictureID = lstInt.FirstOrDefault(); } model.Name = HttpUtility.UrlDecode(model.Name); model.NameAscii = FDIUtils.Slug(model.Name); model.Code = HttpUtility.UrlDecode(CodeSku); _detailDa.Add(model); _detailDa.Save(); var CreateBy = Request["CreateBy"]; //var Percent = Request["Percent"]; var product = new Shop_Product { ProductDetailID = model.ID, CodeSku = model.Code, Quantity = model.QuantityDay, CreateBy = CreateBy, CreateDate = DateTime.Now.TotalSeconds(), IsShow = true, IsDelete = false, }; _da.Add(product); _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu Chưa được thêm mới."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var product = new Shop_Product(); List <Shop_Product> lstProduct; StringBuilder stbMessage; var lsttag = Request["values-arr-tag"]; var lstCate = Request["Value_CategoryValues"]; var images = Request["Value_Images"]; var lstimages = Request["Value_ImagesProducts"]; switch (DoAction) { case ActionType.Add: try { UpdateModel(product); product.CreateDate = DateTime.Now.TotalSeconds(); product.IsDelete = false; product.CreateBy = User.Identity.Name; product.LanguageId = Fdisystem.LanguageId; _productDa.Add(product); _productDa.Save(); msg = new JsonMessage { Erros = false, ID = product.ID.ToString(), Message = string.Format("Đã thêm mới sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Shop_Product_Detail.Name)) }; } catch (Exception) { } break; case ActionType.Edit: try { product = _productDa.GetById(ArrId.FirstOrDefault()); UpdateModel(product); product.IsDelete = false; _productDa.Save(); msg = new JsonMessage { Erros = false, ID = product.ID.ToString(), Message = string.Format("Đã cập nhật sản phẩm: <b>{0}</b>", Server.HtmlEncode(product.Shop_Product_Detail.Name)) }; } catch (Exception) { //Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } break; case ActionType.Delete: lstProduct = _productDa.GetListArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsDelete = true; stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name)); } msg.ID = string.Join(",", ArrId); _productDa.Save(); msg.Message = stbMessage.ToString(); break; case ActionType.Show: lstProduct = _productDa.GetListArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsShow = true; stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name)); } _productDa.Save(); msg.ID = string.Join(",", lstProduct.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.Hide: lstProduct = _productDa.GetListArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Shop_Product_Detail.Name)); } _productDa.Save(); msg.ID = string.Join(",", lstProduct.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; } if (string.IsNullOrEmpty(msg.Message)) { msg.Message = "Không có hành động nào được thực hiện."; msg.Erros = true; } return(Json(msg, JsonRequestBehavior.AllowGet)); }