public ActionResult Coppy(string key) { var msg = new JsonMessage(false, "Coppy dữ liệu thành công."); try { if (key == Keyapi) { var modelNew = new Shop_Product(); var model = _da.GetById(ItemId); modelNew.IsDelete = false; modelNew.IsShow = true; modelNew.ColorID = model.ColorID; modelNew.SizeID = model.SizeID; modelNew.Quantity = 0; modelNew.CodeSku = model.CodeSku + "Coppy"; modelNew.ProductDetailID = model.ProductDetailID; _da.Add(modelNew); _da.Save(); } } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được Coppy."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Add(string key) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); var model = new Shop_Product(); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } UpdateModel(model); model.IsDelete = false; model.IsShow = false; model.DateCreated = DateTime.Now; model.NameAscii = FDIUtils.Slug(model.Name); model.Quantity = 0; model.QuantityOut = 0; _da.Add(model); _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 Coppy(string key) { var msg = new JsonMessage(false, "Coppy dữ liệu thành công."); try { if (key == Keyapi) { var model = _da.GetById(ItemId); var modelNew = new Shop_Product_Detail { Name = model.Name + " coppy", NameAscii = model.NameAscii + "-coppy", Code = model.Code + "-coppy", Price = model.Price, QuantityDay = model.QuantityDay, IsShow = model.IsShow, IsDelete = false, CateID = model.CateID, PictureID = model.PictureID, UnitID = model.UnitID, StartDate = DateTime.Now.TotalSeconds(), Description = model.Description, }; foreach (var item in model.Shop_Product) { var objProduct = new Shop_Product { SizeID = item.SizeID, PriceNew = item.PriceNew, PriceOld = item.PriceOld, QuantityDay = model.QuantityDay, Quantity = 0, CreateDate = model.StartDate, CodeSku = model.Code, IsDelete = false, IsShow = model.IsShow }; modelNew.Shop_Product.Add(objProduct); } _da.Add(modelNew); _da.Save(); } } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được Coppy."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult AjaxForm() { var model = new Shop_Product(); if (DoAction == ActionType.Edit) { model = _productDa.GetById(ArrId.FirstOrDefault()); } ViewBag.Action = DoAction; ViewBag.ActionText = ActionText; return(View(model)); }
public void Add(Shop_Product shopProduct) { try { FDIDB.Shop_Product.Add(shopProduct); } catch (Exception ex) { ex.Message.ToString(); ex.StackTrace.ToString(); } }
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 Add(string key, string codelogin) { var msg = new JsonMessage(false, "Thêm mới dữ liệu thành công."); try { var model = new Shop_Product_Detail(); UpdateModel(model); var lstPicture = Request["Value_ImagesProducts"]; if (!string.IsNullOrEmpty(lstPicture)) { model.Gallery_Picture2 = _da.GetListPictureByArrId(lstPicture); } model.Name = HttpUtility.UrlDecode(model.Name); model.NameAscii = FomatString.Slug(model.Name); model.IsDelete = false; if (IsAdmin) { model.IsShow = true; } else { model.IsShow = false; } var objProduct = new Shop_Product { QuantityDay = model.QuantityDay, Quantity = 0, CreateDate = model.StartDate, CodeSku = model.Code, IsDelete = false, IsShow = model.IsShow }; model.Shop_Product.Add(objProduct); _da.Add(model); _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 Addproduct(string key, string json) { var msg = new JsonMessage(false, "Thêm mới sản phẩm thành công."); try { if (key == Keyapi) { var model = _da.GetProductById(ItemId); var product = _da.GetById(ItemId); var list = new List <Shop_Product>(); foreach (var item in model) { var size = Request["Size_old" + item.ID]; var Type = Request["Type_old" + item.ID]; var price = Request["Price_old" + item.ID]; if (string.IsNullOrEmpty(size)) { list.Add(item); } else { item.SizeID = int.Parse(size); item.TypeID = int.Parse(Type); item.PriceNew = decimal.Parse(price); _da.Save(); } } foreach (var item in list) { _da.DeleteProduct(item); } var stt = ConvertUtil.ToInt32(Request["do_stt"]); for (int i = 1; i <= stt; i++) { var name = Request["Size_add_" + i]; var type = Request["Type_add_" + i]; var price = Request["Price_add_" + i]; if (!string.IsNullOrEmpty(name)) { var obj = new Shop_Product() { ProductDetailID = product.ID, SizeID = int.Parse(name), TypeID = int.Parse(type), IsShow = true, IsDelete = false, }; obj.PriceNew = decimal.Parse(price); _da.AddProduct(obj); } } _da.Save(); } } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được Cập nhật."; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public ActionResult Actions() { var msg = new JsonMessage(); var product = new Shop_Product_Detail(); List <Shop_Product_Detail> lstProduct; StringBuilder stbMessage; var lsttag = Request["values-arr-tag"]; var images = Request["Value_Images"]; var lstCate = Request["Value_CategoryValues"]; var lstimages = Request["Value_ImagesProducts"]; switch (DoAction) { case ActionType.Add: try { UpdateModel(product); product.DateCreate = DateTime.Now.TotalSeconds(); product.IsDelete = false; //product.AgencyID = Utility.AgencyId; product.IsShow = true; //product.LanguageId = Fdisystem.LanguageId; if (!string.IsNullOrEmpty(images)) { product.PictureID = Convert.ToInt32(images); } if (!string.IsNullOrEmpty(lstCate)) { product.Categories = _da.GetListCateByArrId(lstCate); } if (!string.IsNullOrEmpty(lstimages)) { product.Gallery_Picture2 = _da.GetListPictureByArrId(lstimages); } if (string.IsNullOrEmpty(lsttag)) { product.System_Tag = _da.GetListIntTagByArrId(lsttag); } _da.Add(product); _da.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.Name)) }; } catch (Exception) { } break; case ActionType.Edit: try { product = _da.GetById(ArrId.FirstOrDefault()); UpdateModel(product); product.Name = Convert.ToString(product.Name); if (!string.IsNullOrEmpty(images)) { product.PictureID = Convert.ToInt32(images); } product.Categories.Clear(); if (!string.IsNullOrEmpty(lstCate)) { product.Categories = _da.GetListCateByArrId(lstCate); } product.Gallery_Picture2.Clear(); if (!string.IsNullOrEmpty(lstimages)) { product.Gallery_Picture2 = _da.GetListPictureByArrId(lstimages); } product.System_Tag.Clear(); if (!string.IsNullOrEmpty(lsttag)) { product.System_Tag = _da.GetListIntTagByArrId(lsttag); } _da.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.Name)) }; } catch (Exception) { } break; case ActionType.Delete: lstProduct = _da.GetListProductDetailByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsDelete = true; stbMessage.AppendFormat("Đã xóa <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } msg.ID = string.Join(",", ArrId); _da.Save(); msg.Message = stbMessage.ToString(); break; case ActionType.Show: lstProduct = _da.GetListProductDetailByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsShow = true; stbMessage.AppendFormat("Đã hiển thị <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } _da.Save(); msg.ID = string.Join(",", lstProduct.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.Hide: lstProduct = _da.GetListProductDetailByArrId(ArrId); stbMessage = new StringBuilder(); foreach (var item in lstProduct) { item.IsShow = false; stbMessage.AppendFormat("Đã ẩn <b>{0}</b>.<br />", Server.HtmlEncode(item.Name)); } _da.Save(); msg.ID = string.Join(",", lstProduct.Select(o => o.ID)); msg.Message = stbMessage.ToString(); break; case ActionType.UserModule: var model = _da.GetProductById(ArrId.FirstOrDefault()); product = _da.GetById(ArrId.FirstOrDefault()); var list = new List <Shop_Product>(); foreach (var item in model) { var name = Request["Size_old" + item.ID]; if (string.IsNullOrEmpty(name)) { list.Add(item); } else { item.SizeID = int.Parse(name); //item.SizeID = ConvertUtil.ToInt32(Request["Size_old" + item.ID]); //item.PriceNew = ConvertUtil.ToDecimal(Request["PriceNew_old" + item.ID]); //item.PriceOld = ConvertUtil.ToDecimal(Request["PriceOld_old" + item.ID]); } } foreach (var item in list) { _da.DeleteProduct(item); } var stt = ConvertUtil.ToInt32(Request["do_stt"]); for (int i = 1; i <= stt; i++) { var name = Request["Size_add_" + i]; if (!string.IsNullOrEmpty(name)) { var obj = new Shop_Product() { ProductDetailID = product.ID, //PriceNew = ConvertUtil.ToDecimal(Request["PriceNew_add_" + i]), //PriceOld = ConvertUtil.ToDecimal(Request["PriceOld_add_" + i]), SizeID = int.Parse(name), //SizeID = ConvertUtil.ToInt32(Request["Size_add_" + i]), IsShow = true, IsDelete = false, }; _da.AddProduct(obj); } } _da.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.Name)) }; 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)); }
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)); }
public async Task <ActionResult> Add() { var model = new ProductAppIG4Item(); UpdateModel(model); List <Gallery_Picture> images = new List <Gallery_Picture>(); for (int i = 0; i < Request.Files.Count; i++) { var img = await UploadImage(i); if (img.Code != 200) { return(Json(img)); } var picture = new Gallery_Picture { Type = !string.IsNullOrEmpty(Request["type"]) ? Convert.ToInt32(Request["type"]) : 0, CategoryID = model.CateId, Folder = img.Data.Folder, Name = img.Data.Name, DateCreated = DateTime.Now.TotalSeconds(), IsShow = true, Url = img.Data.Url, IsDeleted = false, }; images.Add(picture); _da.Add(picture); } if (images.Count == 0) { return(Json(new JsonMessage(1000, "Ảnh sản phẩn không được để trống."))); } await _da.SaveAsync(); //lay address var address = customerAddressDA.GetById(model.AddressId, CustomerId); if (address == null) { return(Json(new JsonMessage(1000, "Địa chỉ không tồn tại."))); } var product = new Shop_Product { Name = model.Name, NameAscii = FDIUtils.Slug(FDIUtils.NewUnicodeToAscii(model.Name)), Quantity = model.Quantity, Description = model.Description, PriceNew = model.PriceNew, PictureID = images[0].ID, CustomerID = CustomerId, freeShipFor = model.freeShipFor, HasTransfer = model.HasTransfer, Type = model.Type, IsShow = true, IsDelete = false, AddressId = address.ID, Latitude = address.Latitude.Value, CategoryId = model.CateId.Value, Longitude = address.Longitude.Value, DateCreated = DateTime.Now.TotalSeconds(), CustomerID1 = model.CustomerId1, //Gallery_Picture1 = _productDa.GetListPictureByArrId(images.Select(m => m.ID).ToList()), }; //product.Categories = _productDa.GetListCategoryByArrId(new List<int>() { model.CateId.Value }); _productDa.Add(product); await _productDa.SaveAsync(); return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet)); }
public void AddProduct(Shop_Product shopProductDetail) { FDIDB.Shop_Product.Add(shopProductDetail); }
public void DeleteProduct(Shop_Product shopProductDetail) { FDIDB.Shop_Product.Remove(shopProductDetail); }
public void Add(Shop_Product item) { FDIDB.Shop_Product.Add(item); }
public async Task <ActionResult> Actions() { var msg = new JsonMessage(); var url = Request.Form.ToString(); url = HttpUtility.UrlDecode(url); var model = new Shop_Product_Detail(); var lstArrId = ""; var lstPicture = Request["Value_ImagesProducts"]; switch (DoAction) { case ActionType.Add: UpdateModel(model); model.IsDelete = false; if (IsAdmin) { model.IsShow = true; } else { model.IsShow = false; } var objProduct = new Shop_Product { QuantityDay = model.QuantityDay, Quantity = 0, CreateDate = model.StartDate, CodeSku = model.Code, IsDelete = false, IsShow = model.IsShow }; model.Shop_Product.Add(objProduct); if (!string.IsNullOrEmpty(lstPicture)) { model.Gallery_Picture2 = _da.GetListPictureByArrId(lstPicture); } _da.Add(model); _da.Save(); break; case ActionType.View: msg = _api.Coppy(UserItem.AgencyID, ArrId.FirstOrDefault()); break; case ActionType.Edit: model = _da.GetById(ArrId.FirstOrDefault()); UpdateModel(model); if (!IsAdmin) { model.IsShow = false; } model.Gallery_Picture2.Clear(); if (!string.IsNullOrEmpty(lstPicture)) { model.Gallery_Picture2 = _da.GetListPictureByArrId(lstPicture); } _da.Save(); break; case ActionType.Active: msg = _api.Active(url, CodeLogin(), UserItem.UserId); break; case ActionType.NotActive: msg = _api.NotActive(url, CodeLogin(), UserItem.UserId); break; case ActionType.UserModule: msg = _api.Addproduct(UserItem.AgencyID, url); break; case ActionType.Show: lstArrId = string.Join(",", ArrId); msg = _api.ShowHide(lstArrId, true); break; case ActionType.Hide: lstArrId = string.Join(",", ArrId); msg = _api.ShowHide(lstArrId, false); break; case ActionType.Delete: lstArrId = string.Join(",", ArrId); msg = _api.Delete(lstArrId); break; default: msg.Message = "Bạn chưa được phân quyền cho chức năng này."; msg.Erros = true; break; } return(Json(msg, JsonRequestBehavior.AllowGet)); }
public void Delete(Shop_Product shopProduct) { FDIDB.Shop_Product.Remove(shopProduct); }