public async Task <IActionResult> Edit(int id, [Bind("Id,Path,ProductId")] ProductPhotos productPhotos) { if (id != productPhotos.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productPhotos); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductPhotosExists(productPhotos.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Description", productPhotos.ProductId); return(View(productPhotos)); }
protected void UploadPhotoDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e) { byte[] imageFile = e.Values["UploadBytes"] as byte[]; if ((imageFile == null) || (imageFile.Length == 0)) { e.Cancel = true; this.UploadErrorMessage.Visible = false; } else { try { byte[] fullImage = ProductPhotos.ResizeImageFile(imageFile, SueetiePhotoSize.Full); byte[] mediumImage = ProductPhotos.ResizeImageFile(imageFile, SueetiePhotoSize.Medium); byte[] smallImage = ProductPhotos.ResizeImageFile(imageFile, SueetiePhotoSize.Small); e.Values.Add("bytesFull", fullImage); e.Values.Add("bytesMedium", mediumImage); e.Values.Add("bytesSmall", smallImage); e.Values.Remove("UploadBytes"); bool flag = this.PhotoGridView.Rows.Count == 0; e.Values.Add("useAsPreview", flag); this.UploadErrorMessage.Visible = false; } catch { e.Cancel = true; this.UploadErrorMessage.Visible = true; throw; } } }
public async Task <IActionResult> NewProduct([FromForm] AddProductVM productVm) { Product product = new Product(); product.BrandId = productVm.BrandId; product.Description = productVm.Description; product.Model = productVm.Model; product.PriceBy = productVm.PriceBy; if (ModelState.IsValid) { await ctx.Products.AddAsync(product); ctx.SaveChanges(); if (productVm.Files != null) { foreach (var uploadedFile in productVm.Files) { // путь к папке Files string path = "/Files/" + uploadedFile.FileName; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } ProductPhotos photo = new ProductPhotos { ProductId = product.ProductId, Path = path }; ctx.ProductPhotos.Add(photo); } ctx.SaveChanges(); } } return(Ok()); }
public JsonResult addPhotos(AddProductPhotosModel addphotoModel) { ResponseModel result = new ResponseModel(); if (addphotoModel.PhotoList != null && addphotoModel.PhotoList.Count > 0) { try { foreach (HttpPostedFileWrapper item in addphotoModel.PhotoList) { ProductPhotos photo = new ProductPhotos(); photo.ProductID = addphotoModel.ProductID; string file_name = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; string base_file_path = WebConfigurationManager.AppSettings["BaseProductFileAddress"]; string base_file_address = HttpContext.Server.MapPath(base_file_path); string base_path = Path.Combine(base_file_address, file_name); _imgM.SaveProductImage(item, base_path); photo.Photo = file_name; photo.IsMain = false; _proM.AddPhotosToProduct(photo); } result.IsSuccess = true; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; } } return(Json(result)); }
public async Task <IActionResult> Add(Products product) { if (ModelState.IsValid) { Products new_product = new Products(); new_product.ProductCategoryID = product.ProductCategoryID; new_product.Description = product.Description; new_product.Description_Az = product.Description_Az; new_product.Description_Ru = product.Description_Ru; new_product.Info = product.Info; new_product.Info_Az = product.Info_Az; new_product.Info_Ru = product.Info_Ru; new_product.IsActive = product.IsActive; new_product.Name = product.Name; new_product.Price = product.Price; new_product.Discount = product.Discount; db.Products.Add(new_product); foreach (var photo in product.PhotoNames) { ProductPhotos productPhoto = new ProductPhotos(); productPhoto.Product = new_product; productPhoto.Photo = photo; db.ProductPhotos.Add(productPhoto); } await db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ProductCategoryID"] = new SelectList(db.ProductCategories, "ID", "CategoryName_Az"); return(View(product)); }
public ResponseModel AddPhotosToProduct(ProductPhotos addPhoto) { ResponseModel result = new ResponseModel(); _photoRepo.Insert(addPhoto); result.IsSuccess = true; return(result); }
protected void PhotoGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("SelectAsPreview")) { int photoID = Convert.ToInt32(e.CommandArgument); ProductPhotos.SetAdPreviewPhoto(base.CurrentSueetieProduct.ProductID, photoID); this.PhotoGridView.DataBind(); } }
public async Task <IActionResult> Create([Bind("Id,Path,ProductId")] ProductPhotos productPhotos) { if (ModelState.IsValid) { _context.Add(productPhotos); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Description", productPhotos.ProductId); return(View(productPhotos)); }
public ResponseModel AddProduct(AddProductModel addProduct) { ResponseModel result = new ResponseModel(); result = ValidateAddProduct(addProduct); if (!result.IsSuccess) { return(result); } using (var t = new TransactionScope()) { try { UserProducts new_p = new UserProducts(); new_p.UserID = addProduct.UserID; new_p.CreateDate = DateTime.Now; new_p.Description = addProduct.Description; new_p.IsPublish = addProduct.IsPublish; new_p.Keywords = addProduct.Keywords; new_p.Price = addProduct.Price; new_p.Tags = addProduct.Tags; new_p.Name = addProduct.Name; new_p.Uri = new PostManager().GenerateUriFormat(addProduct.Uri); new_p.ID = _proRepo.Insert(new_p); if (addProduct.MainImage != null) { string file_name = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; string baseMap = Path.Combine(addProduct.BasePhotoPath, file_name); _imM.SaveProductImage(addProduct.MainImage, baseMap); ProductPhotos mainPhoto = new ProductPhotos(); mainPhoto.IsMain = true; mainPhoto.Photo = file_name; mainPhoto.ProductID = new_p.ID; _photoRepo.Insert(mainPhoto); } if (addProduct.Photos != null) { foreach (var item in addProduct.Photos) { string file_name = Guid.NewGuid().ToString().Replace("-", "") + ".jpg"; string baseMap = Path.Combine(addProduct.BasePhotoPath, file_name); _imM.SavePostMainPage(item, baseMap); ProductPhotos mainPhoto = new ProductPhotos(); mainPhoto.IsMain = false; mainPhoto.Photo = file_name; mainPhoto.ProductID = new_p.ID; _photoRepo.Insert(mainPhoto); } } result.Message = "Ürün başarı ile eklendi!"; result.IsSuccess = true; t.Complete(); } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; t.Dispose(); } } return(result); }