//for learning only public ViewResult AutoProperty() { //create a new Product object ProductModels myProduct = new ProductModels(); //set the property value myProduct.FirstName = "Sean"; myProduct.LastName = "Cheng"; myProduct.FullName = "Brian Leung"; //generate the view return View("Result", myProduct); }
public PartialViewResult View(string id) { ProductModels model = GetDetail(id); return(PartialView("_View", model)); }
public ActionResult Edit(ProductModels model) { try { List <string> ListNotChangeImg = new List <string>(); byte[] photoByte = null; if (!string.IsNullOrEmpty(model.ImageURL)) { model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image200_100, ""); model.RawImageUrl = model.ImageURL; } if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.RawImageUrl = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; if (!string.IsNullOrEmpty(model.ImageURL)) { model.ImageURL = model.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, ""); ListNotChangeImg.Add(model.ImageURL); } } if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } if (!string.IsNullOrEmpty(model.RawImageUrl)) { model.ListImageUrl.Add(model.RawImageUrl); } //======== Dictionary <int, byte[]> lstImgByte = new Dictionary <int, byte[]>(); var ListImage = model.ListImg.Where(x => !x.IsDelete).ToList(); foreach (var item in ListImage) { if (item.PictureUpload != null && item.PictureUpload.ContentLength > 0) { if (!string.IsNullOrEmpty(item.ImageURL)) { item.ImageURL = item.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, ""); ListNotChangeImg.Add(item.ImageURL); } Byte[] imgByte = new Byte[item.PictureUpload.ContentLength]; item.PictureUpload.InputStream.Read(imgByte, 0, item.PictureUpload.ContentLength); item.PictureByte = imgByte; item.ImageURL = Guid.NewGuid() + Path.GetExtension(item.PictureUpload.FileName); item.PictureUpload = null; lstImgByte.Add(item.OffSet, imgByte); model.ListImageUrl.Add(item.ImageURL); } else { if (!string.IsNullOrEmpty(item.ImageURL)) { item.ImageURL = item.ImageURL.Replace(Commons._PublicImages, "").Replace(Commons.Image100_100, ""); model.ListImageUrl.Add(item.ImageURL); } } } //==================== string msg = ""; model.Type = (byte)Commons.EProductType.Land; var result = _factory.UpdateProduct(model, ref msg); if (result) { if (ListNotChangeImg != null && ListNotChangeImg.Any()) { //Delete image on forder foreach (var item in ListNotChangeImg) { if (!item.Equals(Commons.Image200_100)) { var filePath = Server.MapPath("~/Uploads/Images/Product/" + item); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } } } if (!string.IsNullOrEmpty(model.RawImageUrl) && model.PictureByte != null) { var path = Server.MapPath("~/Uploads/Images/Product/" + model.RawImageUrl); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.RawImageUrl, ref photoByte); } foreach (var item in ListImage) { if (!string.IsNullOrEmpty(item.ImageURL) && item.PictureByte != null) { var path = Server.MapPath("~/Uploads/Images/Product/" + item.ImageURL); MemoryStream ms = new MemoryStream(lstImgByte[item.OffSet], 0, lstImgByte[item.OffSet].Length); ms.Write(lstImgByte[item.OffSet], 0, lstImgByte[item.OffSet].Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, item.ImageURL, ref photoByte); } } return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { NSLog.Logger.Error("Land_Edit: ", ex); model = GetDetail(model.ID); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(new HttpStatusCodeResult(400, ex.Message)); } }
public bool UpdateProduct(ProductModels model, ref string msg) { bool result = true; using (DataContext cxt = new DataContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var itemUpdate = cxt.dbProduct.Where(x => x.ID == model.ID).FirstOrDefault(); if (itemUpdate != null) { //itemUpdate.ID = model.ID; itemUpdate.Name = model.Name; itemUpdate.Phone = model.Phone; itemUpdate.Address = model.Address; itemUpdate.Length = model.Length; itemUpdate.Width = model.Width; itemUpdate.Acreage = model.Acreage; itemUpdate.Price = model.Price; itemUpdate.LocationID = model.LocationID; itemUpdate.Type = model.Type; itemUpdate.Right = model.Right; itemUpdate.BedRoom = model.BedRoom; itemUpdate.LivingRoom = model.LivingRoom; itemUpdate.BathRoom = model.BathRoom; itemUpdate.Floor = model.Floor; itemUpdate.Description = model.Description; itemUpdate.Phone1 = model.Phone1; itemUpdate.Address1 = model.Address1; itemUpdate.Phone2 = model.Phone2; itemUpdate.Address2 = model.Address2; itemUpdate.IsActive = model.IsActive; itemUpdate.Segment = model.Segment; ///// update image if (model.ListImageUrl != null && model.ListImageUrl.Count > 0) { var images = cxt.dbImage.Where(x => x.ProductID == model.ID).ToList(); if (images != null) { cxt.dbImage.RemoveRange(images); } var lstEImage = new List <Image>(); model.ListImageUrl.ForEach(x => { lstEImage.Add(new Image { ID = Guid.NewGuid().ToString(), ImageUrL = x, ProductID = model.ID }); }); cxt.dbImage.AddRange(lstEImage); } cxt.SaveChanges(); transaction.Commit(); } } catch (Exception ex) { NSLog.Logger.Error("Không thể cập nhập cho sản phẩm này. Làm ơn kiểm tra lại!", ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } return(result); }
public ActionResult Post(ProductModels product) { this._productService.Addproduct(product); return(Ok()); }
void BindModels() { gvCurrentModel.DataSource = ProductModels.GetModelsByProductID(productID); gvCurrentModel.DataBind(); }
public void Click() { ProductModels.Clear(); FillProductModels(); }
public ActionResult ListSeller(ProductModels product) { product.SubCategory = ProductManagers.GetSubCategory(); return(View(product)); }
// GET: ProductModels/Delete/5 public ActionResult Agregar(int?hdfId, string hdfIdSesion = "", string desAdicional = "", int cantidad = 1) { if (hdfId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductModels productModels = db.ProductModels.Find(hdfId); if (hdfIdSesion == null) { return(HttpNotFound()); } //List<ProductOrderModels> lobeProdsPedido = (List<ProductOrderModels>)Session[hdfIdSesion + "lobeProdsPedido"]; List <ProductOrderModels> lobeProdsPedido = (List <ProductOrderModels>)Session["lobeProdsPedido"]; ProductOrderModels oProd; if (lobeProdsPedido != null && lobeProdsPedido.Count > 0) { UtilModels.idProd = productModels.Id; oProd = lobeProdsPedido.Find(UtilModels.FiltrarProdOrder); if (oProd != null) { oProd.cantidadPedida += cantidad; oProd.DescripcionAdicional += "-" + desAdicional; } else { oProd = new ProductOrderModels() { Id = productModels.Id, IdProducto = productModels.Id, Nombre = productModels.Nombre, DescripcionAdicional = desAdicional, PrecioCosto = productModels.PrecioCosto, PrecioVenta = productModels.PrecioVenta, UrlImagen = productModels.UrlImagen, cantidadPedida = cantidad }; lobeProdsPedido.Add(oProd); } } else { lobeProdsPedido = new List <ProductOrderModels>(); oProd = new ProductOrderModels() { Id = productModels.Id, IdProducto = productModels.Id, Nombre = productModels.Nombre, DescripcionAdicional = desAdicional, PrecioCosto = productModels.PrecioCosto, PrecioVenta = productModels.PrecioVenta, UrlImagen = productModels.UrlImagen, cantidadPedida = cantidad }; lobeProdsPedido.Add(oProd); } //Session[hdfIdSesion + "lobeProdsPedido"] = lobeProdsPedido; Session["lobeProdsPedido"] = lobeProdsPedido; string strBus = (string)Session["busqueda"]; return(RedirectToAction("Index", "ProductModels", new { strBus = strBus, idSesion = hdfIdSesion })); }
public void Addproduct(ProductModels product) { _productlist.Add(product); }
public string GetCate_Name(ProductModels models) { var cate_models = CateProductCollection.AsQueryable <CateProductModels>().SingleOrDefault(x => x.ID == models.CategoryID); return(cate_models.Name); }
public string GetBrand_Name(ProductModels models) { var brand_models = BrandCollection.AsQueryable <BrandModels>().SingleOrDefault(x => x.ID == models.BrandID); return(brand_models.Name); }
public IActionResult Create(ProductModels sp) { danhSach.Add(sp); return(View("Index", danhSach)); }
public ActionResult Create() { ProductModels model = new ProductModels(); return(View(model)); }
public async Task WhenDeletingExistingProduct_ThenNoContentIsReturned() { ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(ProductModels.GetCreateModel()); ApiResponse <Response> deleteResponse = await _productApiClient.Delete(createResponse.Response.Id); Assert.That(deleteResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.NoContent)); }
public ActionResult Create(ProductModels model) { try { byte[] photoByte = null; if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[model.PictureUpload.ContentLength]; model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength); model.PictureByte = imgByte; model.RawImageUrl = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName); model.PictureUpload = null; photoByte = imgByte; } if (!ModelState.IsValid) { return(View(model)); } if (!string.IsNullOrEmpty(model.RawImageUrl)) { model.ListImageUrl.Add(model.RawImageUrl); } //======== Dictionary <int, byte[]> lstImgByte = new Dictionary <int, byte[]>(); var ListImage = model.ListImg.Where(x => !x.IsDelete).ToList(); foreach (var item in ListImage) { if (item.PictureUpload != null && item.PictureUpload.ContentLength > 0) { Byte[] imgByte = new Byte[item.PictureUpload.ContentLength]; item.PictureUpload.InputStream.Read(imgByte, 0, item.PictureUpload.ContentLength); item.PictureByte = imgByte; item.ImageURL = Guid.NewGuid() + Path.GetExtension(item.PictureUpload.FileName); item.PictureUpload = null; lstImgByte.Add(item.OffSet, imgByte); model.ListImageUrl.Add(item.ImageURL); } } //==================== string msg = ""; model.Type = (byte)Commons.EProductType.Land; bool result = _factory.InsertProduct(model, ref msg); if (result) { if (!string.IsNullOrEmpty(model.RawImageUrl) && model.PictureByte != null) { var path = Server.MapPath("~/Uploads/Images/Product/" + model.RawImageUrl); MemoryStream ms = new MemoryStream(photoByte, 0, photoByte.Length); ms.Write(photoByte, 0, photoByte.Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.RawImageUrl, ref photoByte); } foreach (var item in ListImage) { if (!string.IsNullOrEmpty(item.ImageURL) && item.PictureByte != null) { var path = Server.MapPath("~/Uploads/Images/Product/" + item.ImageURL); MemoryStream ms = new MemoryStream(lstImgByte[item.OffSet], 0, lstImgByte[item.OffSet].Length); ms.Write(lstImgByte[item.OffSet], 0, lstImgByte[item.OffSet].Length); System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true); ImageHelper.Me.SaveCroppedImage(imageTmp, path, item.ImageURL, ref photoByte); } } return(RedirectToAction("Index")); } else { ModelState.AddModelError("Name", msg); return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("Land_Create: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult Edit(int id, int catID) { ProductModels obj = _service.GetProductByID(id, catID); return(View("Create", obj)); }
private void Initialize() { List <string> Product_List = ProductID.Split(',').ToList(); Db2HoldReason.Conditions = string.Format("where lot_type='Production' and prodspec_id in ('{2}') and claim_time between '{0}' and '{1}'", StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime.ToString("yyyy-MM-dd HH:mm:ss"), string.Join("','", Product_List)); var Models = Db2HoldReason.GetEntities().EntityList; //if (Models.Count == 0) return; //lotCount int lotCount = Models.Select(s => s.Lot_ID).Distinct().Count(); //所有Hold数据 var HoldModels = Models.Where(w => w.Hold_Type != "" && w.Ope_Category.Substring(w.Ope_Category.Length - 4) == "Hold"); //5码的Hold数据 var HoldModels_5 = HoldModels.Where(w => w.Hold_Reason_Code.Length == 5); //4码的hold数据 var HoldModels_4 = HoldModels.Where(w => w.Hold_Reason_Code.Length == 4); List <FRPD> PD_List = new List <FRPD>(); if (HoldModels_4.Count() > 0) { PDCatcher.Conditions = string.Format("where pd_id in ('{0}')", string.Join("','", HoldModels_4.Select(s => s.PD_ID))); PD_List = PDCatcher.GetEntities().EntityList.ToList(); } var Departments = DepartmentCatcher.GetEntities().EntityList; foreach (var department in Departments) { //对每个部门计算该部门对应的hold list var list5 = HoldModels_5.Where(w => w.Hold_Reason_Code.Substring(0, 1) == department.Code_ID); var list4 = HoldModels_4.Where(w => PD_List.Where(p => p.Department == department.Code_ID).DefaultIfEmpty().Select(s => s.PD_ID).Contains(w.PD_ID)); var list = list4.Union(list5); List <ReqRpt014DepartmentTableEntity> l = new List <ReqRpt014DepartmentTableEntity>(); if (list.Count() == 0) //如果没有元素,则不进行查找 { DepartmentModels.Add(new ReqRpt014DepartmentTableModel(l) { Department = department.Description }); continue; } //如果存在元素,则进行下去 var ReasonList = list.GroupBy(g => g.Hold_Reason_Code).Select(s => new { Hold_Reason_Code = s.Key, Hold_Count = s.Count() }); foreach (var item in ReasonList) { ReqRpt014DepartmentTableEntity tableEntity = new ReqRpt014DepartmentTableEntity() { HoldCode = item.Hold_Reason_Code, HoldRate = item.Hold_Count / lotCount, LotCount = list.Where(w => w.Hold_Reason_Code == item.Hold_Reason_Code).Select(s => s.Lot_ID).Distinct().Count() }; l.Add(tableEntity); } DepartmentModels.Add(new ReqRpt014DepartmentTableModel(l) { Department = department.Description }); } //by product部分 foreach (string prod in Product_List) { var list = HoldModels.Where(s => s.ProdSpec_ID == prod); List <ReqRpt014ProductTableEntity> l = new List <ReqRpt014ProductTableEntity>(); if (list is null) //如果没有元素,则不进行查找 { ProductModels.Add(new ReqRpt014ProductTableModel(l) { ProductID = prod }); continue; } //如果存在元素,则进行下去 var ReasonList = list.GroupBy(g => g.Hold_Reason_Code).Select(s => new { Hold_Reason_Code = s.Key, HoldCount = s.Count() }); foreach (var item in ReasonList) { ReqRpt014ProductTableEntity tableEntity = new ReqRpt014ProductTableEntity() { HoldCode = item.Hold_Reason_Code, HoldRate = item.HoldCount / lotCount, LotCount = list.Where(w => w.Hold_Reason_Code == item.Hold_Reason_Code).Select(s => s.Lot_ID).Distinct().Count() }; l.Add(tableEntity); } ProductModels.Add(new ReqRpt014ProductTableModel(l) { ProductID = prod }); } }
public ActionResult Edit(ProductModels obj) { _service.UpdateProduct(obj); return(RedirectToAction("Index", new { id = obj.CategoryID_FK })); }
protected void gvCurrentModel_RowDeleting(object sender, GridViewDeleteEventArgs e) { ProductModels.Delete(int.Parse(gvCurrentModel.DataKeys[e.RowIndex].Value.ToString())); BindToModel(); }
public bool InsertProduct(ProductModels model, ref string msg) { bool result = true; using (DataContext cxt = new DataContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { Product item = new Product(); string id = Guid.NewGuid().ToString(); item.ID = id; item.Name = model.Name; item.Phone = model.Phone; item.Address = model.Address; item.Length = model.Length; item.Width = model.Width; item.Acreage = model.Acreage; item.Price = model.Price; item.LocationID = model.LocationID; item.Type = model.Type; item.Right = model.Right; item.BedRoom = model.BedRoom; item.LivingRoom = model.LivingRoom; item.BathRoom = model.BathRoom; item.Floor = model.Floor; item.Description = model.Description; item.Phone1 = model.Phone1; item.Address1 = model.Address1; item.Phone2 = model.Phone2; item.Address2 = model.Address2; item.IsActive = model.IsActive; item.CreatedDate = DateTime.Now; item.ModifiedDate = DateTime.Now; item.CreatedUser = model.CreatedUser; item.ModifiedUser = model.ModifiedUser; item.Segment = model.Segment; cxt.dbProduct.Add(item); //////////////////////////////////// Save table Image var lstEImage = new List <Image>(); model.ListImageUrl.ForEach(x => { lstEImage.Add(new Image { ID = Guid.NewGuid().ToString(), ImageUrL = x, ProductID = id }); }); cxt.dbImage.AddRange(lstEImage); cxt.SaveChanges(); transaction.Commit(); } catch (Exception ex) { NSLog.Logger.Error("Không thể thêm sản phẩm!", ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } return(result); }
public ActionResult EditProduct(List <HttpPostedFileBase> Photo, EditProductViewModel product) { if (ModelState.IsValid) { AppDbContext dbContext = new AppDbContext(); ModelModels model = dbContext.getModels.SingleOrDefault(m => m.Id == product.ModelId); ProductModels oldProduct = dbContext.getProducts.SingleOrDefault(p => p.Id == product.Id); BrandModels brand = dbContext.getBrands.SingleOrDefault(b => b.BrandId == model.BrandId); CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == model.CategoryId); EditProductModels editProduct = new EditProductModels { Id = Guid.NewGuid(), Model = model.Name, Brand = brand.Brand, Category = category.Category, Price = oldProduct.Price, Color = oldProduct.Color, Storage = oldProduct.Storage, Processor = oldProduct.Processor, Memory = oldProduct.Memory, Display = oldProduct.Display, Details = oldProduct.Details, EditedBy = User.Identity.Name, EditedDate = DateTime.Now, ProductId = product.Id }; dbContext.addEditedProduct(editProduct); ProductModels productModels = new ProductModels(); productModels.Id = product.Id; productModels.Price = product.Price; productModels.Color = product.Color; productModels.Storage = product.Storage; productModels.Processor = product.Processor; productModels.Memory = product.Memory; productModels.Display = product.Display; productModels.Details = product.Details; productModels.ModelId = product.ModelId; productModels.Photos = new List <ProductPhoto>(); List <ProductPhoto> photos = new List <ProductPhoto>(); foreach (var photo in Photo) { if (photo != null) { List <ProductPhoto> Photos = dbContext.getProductPhotos(product.Id).ToList(); if (Photos.Count > 0) { foreach (var item in Photos) { System.IO.File.Delete(item.Src); dbContext.deleteProductPhoto(item.Id); } } var fileName = Path.GetFileName(photo.FileName); var path = "/Public/Products/" + model.Name; var photoUrl = Server.MapPath(path); var photoTitle = Path.GetFileNameWithoutExtension(photo.FileName); var uniqName = Guid.NewGuid().ToString() + "_" + fileName; if (!Directory.Exists(photoUrl)) { Directory.CreateDirectory(photoUrl); } var photoPath = Path.Combine(photoUrl, uniqName); ProductPhoto newPhoto = new ProductPhoto { Path = path, Src = photoPath, Title = uniqName, ProductId = product.Id }; photos.Add(newPhoto); photo.SaveAs(photoPath); } } dbContext.addProductPhoto(photos); dbContext.updateProduct(productModels); return(RedirectToAction("Index")); } return(View(product)); }
// GET: ProductList public ActionResult ProductList() { ProductModels product = new ProductModels(); return(View(product)); }