// GET: Products/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int idx = id ?? 0; string ApiEndPoint = ApiUrl + "api/ProductApi/Get/" + idx; HttpClient client = new HttpClient(); HttpResponseMessage response = client.GetAsync(ApiEndPoint).Result; string result = response.Content.ReadAsStringAsync().Result.ToString(); ProductViewModels ProdVM = JsonConvert.DeserializeObject <ProductViewModels>(result); //ProductViewModels result = service.GetProductById(idx); if (result == null) { return(HttpNotFound()); } //ViewBag.SupplierId = new SelectList(service.GetCompanyName(), "id", "CompanyName"); return(View(ProdVM)); }
// // GET: /Admin/AminProduct/Create public ActionResult Create() { ProductViewModels sp = new ProductViewModels(); sp.dsLoai1 = LoaiBus.DanhSach(); return(View(sp)); }
private ProductViewModels LoadSelectlist(ProductViewModels model) { model.BrandList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.Product_brand), "ClassificationId", "ClassificationNM"); model.MadeInList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.xuat_xu), "ClassificationId", "ClassificationNM"); model.UnitsList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.don_vi), "ClassificationId", "ClassificationNM"); model.CorlorList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.color_list), "ClassificationId", "ClassificationNM"); model.SupportTimeList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.support_time), "ClassificationId", "ClassificationNM"); model.TranTypeList = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.tran_type), "ClassificationId", "ClassificationNM"); model.Status_Productlst = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.statusproduct_type), "ClassificationId", "ClassificationNM"); model.lstSize = new SelectList(cms_db.GetCatagoryForSelectList((int) EnumCore.ClassificationScheme.kich_thuoc), "ClassificationId", "ClassificationNM"); return(model); }
public ActionResult Create(ProductViewModels model) { // Checks if there is any issues with the data posted to the server, based on the data annotations added to the properties of your model. if (ModelState.IsValid) { var newProduct = new Product { // set all the properties in the 'ProductViewModels' to the properties in the 'Product' (entity) Name = model.Name, Description = model.Description, Price = model.Price, ImageURL = model.ImageURL, isFeatured = model.isFeatured, Category = CategoriesService.Instance.GetCategory(model.CategoryId) }; ProductsService.Instance.SaveProduct(newProduct); return(RedirectToAction("ProductsTable")); } else { return(new HttpStatusCodeResult(500)); } }
public ActionResult Create() { ViewBag.KindID = new SelectList(db.ProductKinds.Where(s => s.EnterpriseID == AccontData.EnterpriseID), "ID", "Name"); var model = new ProductViewModels(); return(View(model)); }
public ActionResult Edit(ProductViewModels product) { var temp = db.Products.FirstOrDefault(s => s.ID == product.ID); //防止企业用户串号修改 if (AccontData.UserType == UserType.Enterprise && temp.EnterpriseID != AccontData.EnterpriseID) { return(this.ToError("错误", "没有该操作权限", Url.Action("Index"))); } if (ModelState.IsValid) { var t = db.Products.FirstOrDefault(s => s.ID == product.ID); t.ID = product.ID; t.Name = product.Name; t.Count = product.Count; //t.EnterpriseID = AccontData.EnterpriseID; t.Info = product.Info; t.KindID = product.KindID; t.Price = product.Price; t.OriginalPrice = product.OriginalPrice; t.Release = product.Release; t.Sort = product.Sort; t.TotalSales = product.TotalSales; t.Type = product.Type; t.Images = string.Join(",", product.Images.Images); db.SaveChanges(); //db.Entry(product).State = EntityState.Modified; //db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.KindID = new SelectList(db.ProductKinds, "ID", "Name", product.KindID); return(View(product)); }
public ActionResult Edit(ProductViewModels model) { if (ModelState.IsValid) { var existingProduct = ProductsService.Instance.GetProduct(model.ID); existingProduct.Name = model.Name; existingProduct.Description = model.Description; existingProduct.Price = model.Price; existingProduct.isFeatured = model.isFeatured; existingProduct.Category = null; // marked null as the reference key is changed below existingProduct.CategoryID = model.CategoryId; if (!string.IsNullOrEmpty(model.ImageURL)) { existingProduct.ImageURL = model.ImageURL; } ProductsService.Instance.UpdatepProduct(existingProduct); return(RedirectToAction("ProductsTable")); } else { return(new HttpStatusCodeResult(500)); } }
public void FillProductList() { if (SelectedSearchId == 0) { return; } ProductViewModels.Clear(); Products = new List <ProductDto>(); GetProductBySearchTypeDto requestDto = new GetProductBySearchTypeDto { ProductSearchTypeId = SelectedSearchId }; switch (SelectedSearchId) { case 3: requestDto.ExtraParams = new Dictionary <string, string> { { "ZoneId", UserContext.GetUserZoneId().ToString() } }; break; default: requestDto.ExtraParams = null; break; } Products = _restApiClient.GetProductBySearchId(requestDto); var porductsModels = Products.Select(ProductViewModel.FromRest); foreach (var model in porductsModels) { ProductViewModels.Add(model); } }
public ActionResult CurrentCart(int?id) { var currentCart = Operation.GetCurrentCart(); var userid = HttpContext.User.Identity.GetUserId(); ProductViewModels product = new ProductViewModels(); product.PId = Convert.ToInt32(id); TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities(); var query = from c in db.buyitemdetailtbl where c.mid == userid && c.pid == id select c; if (query.Count() > 0) { return(PartialView("_btnBuy")); } foreach (var cartitem in currentCart) { if (cartitem.Id == id) { return(PartialView("_btnAdded", product)); } } return(PartialView("_btnAddCart", product)); }
public ProductsController() { ProductModel = new ProductViewModels(); var productCategories = GetProductCategories(); ProductModel.ProductCategories = productCategories; }
public async Task <IActionResult> Create(ProductViewModels model) { if (ModelState.IsValid) { string primaryImage = UploadedFile(model.PrimaryImage); string secondaryImage1 = UploadedFile(model.SecondaryImage1); string secondaryImage2 = UploadedFile(model.SecondaryImage2); string secondaryImage3 = UploadedFile(model.SecondaryImage3); Product product = new Product { Name = model.Name, Description = model.Description, Price = model.Price, CategoryID = model.CategoryID, PrimaryImage = primaryImage, SecondaryImage1 = secondaryImage2, SecondaryImage2 = secondaryImage2, SecondaryImage3 = secondaryImage3, Instock = model.Instock, }; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public ActionResult Create(ProductViewModels product) { var tempuser = db.Users.FirstOrDefault(s => s.Id == AccontData.UserID); //防止企业用户串号修改 if (AccontData.UserType == UserType.Enterprise && tempuser.EnterpriseID != AccontData.EnterpriseID) { return(this.ToError("错误", "没有该操作权限", Url.Action("Index"))); } if (ModelState.IsValid) { var model = new Product { Name = product.Name, Count = product.Count, EnterpriseID = AccontData.EnterpriseID, Images = string.Join(",", product.Images.Images), Info = product.Info, KindID = product.KindID, Price = product.Price, OriginalPrice = product.OriginalPrice, Release = product.Release, Sort = product.Sort, TotalSales = product.TotalSales, Type = product.Type }; db.Products.Add(model); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.KindID = new SelectList(db.ProductKinds, "ID", "Name", product.KindID); return(View(product)); }
// GET: Product/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IEnumerable <ProductViewModels> vModelList; ProductEntity pe = new ProductEntity(); vModelList = pe.QueryByProductId(id.ToString()); if (vModelList == null) { return(HttpNotFound()); } ProductViewModels vModel = vModelList.ToList()[0]; //Kinds dropdownlist vModel.Kinds = ProductEnumLists.GetInitKinds(); //Category dropdownlist vModel.Categories = ProductEnumLists.GetCategories(vModel.SelectedKinds.ToString()); //這邊為了方便起見,先只回傳一筆,理論上應該是要直接回傳單一個 ViewModel return(View(vModel)); }
public ActionResult Search() { var Key = Request.QueryString["search"]; if (string.IsNullOrEmpty(Key)) { Key = ""; } var model = new ProductViewModels(); var data = _fac.GetList() .Where(x => CommonHelper.RemoveUnicode(x.ProductName.ToLower()).Contains(CommonHelper.RemoveUnicode(Key.ToLower()))) .OrderByDescending(x => x.CreatedDate) .ToList(); if (data != null && data.Any()) { var dataImage = _fac.GetListImage(); data.ForEach(x => { var _Image = dataImage.FirstOrDefault(y => y.ProductId.Equals(x.Id)); if (_Image != null) { if (!string.IsNullOrEmpty(_Image.ImageURL)) { x.ImageURL = Commons.HostImage + "Products/" + _Image.ImageURL; } } }); model.ListProduct = data; } return(View(model)); }
public IActionResult Create(ProductViewModels data, IFormFile f) { try { if (f != null) { if (f.Length > 0) { //D:\School\Ep\SWD62BEP\Solution1\PresentationWebApp\wwwroot\Images\ string newFileName = Guid.NewGuid() + System.IO.Path.GetExtension(f.FileName); string newFileNameWithAbsolutePath = _env.WebRootPath + @"\Images\" + newFileName; using (var stream = System.IO.File.Create(newFileNameWithAbsolutePath)) { f.CopyTo(stream); } data.ImageUrl = @"\Images\" + newFileName; } } _productsService.AddProduct(data); TempData["feedback"] = "Product was added sucessfully"; } catch (Exception ex) { //log error TempData["warning"] = "Product was not added"; } var listofCategories = _categoryService.GetCategories(); ViewBag.Categories = listofCategories; return(View(data)); }
public ActionResult ProductViewModels() { var lstColors = db.Colors.ToList(); ProductViewModels vmDemo = new ProductViewModels(); return(View(vmDemo)); }
//在 Create Page ,dropdownlist 使用 //It is necessary to set string type in parameter or else you will get Internal Server error 500. public JsonResult GetProductCategories(string typeSelected) { ProductViewModels mView = new ProductViewModels(); mView.Categories = ProductEnumLists.GetCategories(typeSelected); return(Json(new { mView.Categories })); }
public ActionResult Search(ProductViewModels model) { try { var listData = _factory.GetListData(model.SearchString, (byte)Commons.EProductType.Package); listData.ForEach(x => { //x.CategoryName = x.ListProductName == null ? "" : string.Join(", ", x.ListProductName); string sItem = ""; int countItem = x.ListProductName.ToList().Count; for (int s = 1; s <= countItem; s++) { sItem += x.ListProductName[s - 1] + (s == countItem ? "" : ", "); if (s % 8 == 0) { sItem += "<br/>"; } } x.CategoryName = sItem; }); model.ListItem = listData; } catch (Exception e) { NSLog.Logger.Error("ProductPackageSearch: ", e); return(new HttpStatusCodeResult(400, e.Message)); } return(PartialView("_ListData", model)); }
public ActionResult Create(ProductViewModels newproduct) { if (ModelState.IsValid) { try { // TODO: Add insert logic here using (CrossOverShoppingCartDBEntities ce = new CrossOverShoppingCartDBEntities()) { ce.Products.Add(new Product() { ProductName = newproduct.ProductName, Price = newproduct.Price, IsActive = newproduct.IsActive?"Y":"N", Cr_datetime = DateTime.Now, Mo_datetime = DateTime.Now }); ce.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(RedirectToAction("Error")); } } return(View(newproduct)); }
public async Task <ActionResult> Create(ProductViewModels model, HttpPostedFileBase Default_files, HttpPostedFileBase[] Detail_files) { try { if (ModelState.IsValid) { Classification _objcata = cms_db.GetObjClasscifiById(model.CategoryId.Value); Product MainModel = model._MainObj; MainModel.CommentCount = 0; MainModel.CrtdDT = DateTime.Now; MainModel.CrtdUserId = long.Parse(User.Identity.GetUserId()); MainModel.CrtdUserName = User.Identity.Name; MainModel.CategoryName = _objcata.ClassificationNM; MainModel.ViewCount = 0; MainModel.StateId = (int)EnumCore.StateType.cho_duyet; MainModel.StateName = "Chờ Duyệt"; //MainModel.BrandNameID = model.BrandNameID; //MainModel.Units = model.Units; //MainModel.CorlorID = model.CorlorID; //MainModel.MadeIn = model.MadeIn; //MainModel.StatusProductType = model.StatusProductType; //MainModel.SupportTimeID = model.SupportTimeID; //MainModel.BrandName = cms_db.GetNameObjClasscifiById(model.BrandNameID); //MainModel.UnitsName = cms_db.GetNameObjClasscifiById(model.Units); //MainModel.CorlorName = cms_db.GetNameObjClasscifiById(model.CategoryId); //MainModel.MadeInName = cms_db.GetNameObjClasscifiById(model.MadeIn); //MainModel.StatusProductTypeName = cms_db.GetNameObjClasscifiById(model.StatusProductType); //MainModel.SupportTimeName = cms_db.GetNameObjClasscifiById(model.SupportTimeID); int rs = await cms_db.CreateProduct(MainModel); if (Default_files != null) { MediaContentViewModels rsdf = await this.SaveDefaultImageForProduct(Default_files, MainModel.ProductId); int rsup = await this.UpdateImageUrlForProduct(rsdf, MainModel); } int SaveDetailImageForProduct = await this.SaveDetailImageForProduct(Detail_files, MainModel.ProductId); //int SaveColorSKU = this.SaveColorSKU(model.ColorSku, MainModel.ProductId); //int SaveProductSize = this.SaveProductSize(model.lstcbsize, MainModel.ProductId); int ach = await cms_db.CreateUserHistory(long.Parse(User.Identity.GetUserId()), Request.ServerVariables["REMOTE_ADDR"], (int)EnumCore.ActionType.Create, "Create", MainModel.ProductId, MainModel.ProductName, "Product", (int)EnumCore.ObjTypeId.san_pham); return(RedirectToAction("Index")); } return(RedirectToAction("Create")); } catch (Exception e) { cms_db.AddToExceptionLog("Create", "ProductManager", e.ToString(), long.Parse(User.Identity.GetUserId())); return(RedirectToAction("Index")); } }
//傳入ViewModel,修改資料 public Boolean Update(ProductViewModels vModel) { string connStr = DBConnClass.GetDBConn(); SqlConnection sqlConnection = new SqlConnection(connStr); SqlCommand cmd = new SqlCommand(); try { cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = @"update producttbl set kind=@kind, category=@category, mid=@mid, name=@name, intro=@intro, price=@price, state=@state, score=@score, picture=@picture where pid=@pid"; //vidiourl=@vidiourl cmd.Connection = sqlConnection; cmd.Parameters.Add("@pid", SqlDbType.Int).Value = vModel.PId; cmd.Parameters.Add("@kind", SqlDbType.Int).Value = vModel.SelectedKinds; cmd.Parameters.Add("@category", SqlDbType.Int).Value = vModel.SelectedCategories; cmd.Parameters.Add("@mid", SqlDbType.NVarChar).Value = vModel.MId; cmd.Parameters.Add("@name", SqlDbType.NVarChar).Value = vModel.Name; cmd.Parameters.Add("@intro", SqlDbType.NVarChar).Value = vModel.Intro; cmd.Parameters.Add("@price", SqlDbType.Int).Value = vModel.Price; cmd.Parameters.Add("@state", SqlDbType.Int).Value = vModel.State; cmd.Parameters.Add("@score", SqlDbType.Int).Value = vModel.Score; cmd.Parameters.Add("@picture", SqlDbType.VarBinary).Value = vModel.Picture ?? null; // cmd.Parameters.Add("@vidiourl", SqlDbType.NVarChar).Value = vModel.VidioUrl ?? null; sqlConnection.Open(); int effectrows; effectrows = cmd.ExecuteNonQuery(); if (effectrows <= 0) { return(false); } else { return(true); } } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { sqlConnection.Close(); } }
public PartialViewResult LoadPagging(int pageIndex, string Id = "", string Key = "", bool isOrther = false) { ProductViewModels model = new ProductViewModels(); var data = new List <ProductModels>(); if (!isOrther) { data = _fac.GetListProduct().Where(z => (string.IsNullOrEmpty(Id) ? 1 == 1 : z.CategoryID.Equals(Id)) && (string.IsNullOrEmpty(Key) ? 1 == 1 : CommonHelper.RemoveUnicode(z.Name.ToLower()).Contains(CommonHelper.RemoveUnicode(Key.ToLower())))).ToList(); } else { var ListCate = Session["Catelogies"] as List <CateSession>; if (ListCate != null && ListCate.Count < 9) { data = _fac.GetListProduct().OrderBy(x => x.Name).ToList(); } else { data = _fac.GetListProduct().Where(x => ListCate.Select(z => z.Id).Contains(x.CategoryID)).OrderBy(x => x.Name).ToList(); } } if (data != null && data.Any()) { model.CateID = Id; model.Key = Key; model.IsOrther = isOrther; data.ForEach(x => { if (!string.IsNullOrEmpty(x.ImageURL)) { x.ImageURL = Commons.HostImage + x.ImageURL; } }); // model.ListProduct = model.ListProduct.OrderByDescending(x => x.CreatedDate).ToList(); model.TotalProduct = data.Count; model.ListProduct = data.OrderByDescending(x => x.CreatedDate).Skip(0).Take(12 * pageIndex).ToList(); var page = 0; if (data.Count % 12 == 0) { page = data.Count / 12; } else { page = Convert.ToInt16(data.Count / 12) + 1; } if (page > pageIndex) { model.TotalPage = pageIndex + 1; } else { model.IsAddMore = true; } } return(PartialView("_ListItem", model)); }
private void RefreshProducts() { ProductViewModels.Clear(); FillProductList(); SelectedProduct = null; }
public ActionResult Details(int Id) { ProductViewModels model = new ProductViewModels(); model.Product = ProductService.Instance.GetProduct(Id); return(View(model)); }
public async Task <IActionResult> Create(ProductViewModels viewModels) { var product = _mapper.Map <Product>(viewModels.Product); if (HttpContext.Request.Form.Files != null) { var fileName = string.Empty; var files = HttpContext.Request.Form.Files; foreach (var file in files) { if (file.Length > 0) { fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); var myUniqueFileName = Convert.ToString(Guid.NewGuid()); var FileExtension = Path.GetExtension(fileName); string newFileName = myUniqueFileName + FileExtension; var imageProduct = new ImageProduct() { Image = newFileName }; product.ImageProducts.Add(imageProduct); string[] contentTypes = new string[] { ".jpg", ".png", ".jpeg" }; if (!contentTypes.Contains(FileExtension)) { return(RedirectToAction("Index", "Products")); } // Combines two strings into a path. fileName = Path.Combine(_hosting.WebRootPath, "photos") + $@"\{newFileName}"; //if you want to store path of folder in database using (FileStream fs = System.IO.File.Create(fileName)) { file.CopyTo(fs); fs.Flush(); } } } if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Brands, "Id", "Name", product.DepartmentId); return(View(product)); } return(View(viewModels)); }
public IActionResult List() { var productViewModel = new ProductViewModels() { products = ProductRepository.Products }; return(View(productViewModel)); }
public ActionResult About() { var article_category = dbContext.Article_categorys.ToList(); var article_manager = dbContext.Article_managers.ToList(); ProductViewModels viewModel = new ProductViewModels(); viewModel.Article_Managers = article_manager; return(View(viewModel)); }
public ActionResult Create() { ProductViewModels model = new ProductViewModels(); model.CatalogryList = new SelectList(cms_db.GetProductCatagory(), "value", "text"); //model.MainCatalogryList = new SelectList(cms_db.GetProductCatagory(), "value", "text"); //model = this.LoadSelectlist(model); return(View(model)); }
public ActionResult Create() { var _productViewModel = new ProductViewModels(); _productViewModel.ComboCategory = _categoryAppService.GetActiveCategorys().Select(x => new SelectListItem { Text = x.CategoryName, Value = Convert.ToString(x.CategoryId) }); return(View(_productViewModel)); }
public ActionResult Details(int ID) { var _model = new ProductViewModels { Product = ProductService.Instance.GetProduct(ID) }; return(View(_model)); }