public ActionResult Create(AddProductViewModel model) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) { var product = Mapper.Map<AddProductViewModel, Entities.Product>(model); ProductManager.Create(product); ProductManager.Save(); //return RedirectToAction("Index", "Home"); return Json(product.Id); } return View(model); }
public MenuPopup(AddProductViewModel viewModel) { InitializeComponent(); BindingContext = viewModel; }
public async Task <ActionResult> Add(AddProductViewModel prd) { if (!ModelState.IsValid) { ViewBag.ProductList = GetProductSelectList(); ViewBag.CategoryList = GetCategorySelectList(); return(View(prd)); } try { if (prd.Product.SupProductId.ToString().Replace("0", "").Replace("-", "").Length == 0) { prd.Product.SupProductId = null; } prd.Product.LastPriceUpdateDate = DateTime.Now; Product model = new Product() { Category = prd.Product.Category, Description = prd.Product.Description, ProductName = prd.Product.ProductName, SalesPrice = prd.Product.SalesPrice, BuyPrice = prd.Product.BuyPrice, Id = prd.Product.Id, AvatarPath = prd.Product.AvatarPath, Barcode = prd.Product.Barcode, CreatedDate = prd.Product.CreatedDate, Invoices = prd.Product.Invoices, LastPriceUpdateDate = prd.Product.LastPriceUpdateDate, ProductType = prd.Product.ProductType, Products = prd.Product.Products, Quantity = prd.Product.Quantity, SupProduct = prd.Product.SupProduct, SupProductId = prd.Product.SupProductId, UnitsInStock = prd.Product.UnitsInStock, UpdatedDate = prd.Product.UpdatedDate }; model.CategoryId = prd.Product.CategoryId; if (prd.PostedFile != null && prd.PostedFile.ContentLength > 0) { var file = prd.PostedFile; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extName = Path.GetExtension(file.FileName); fileName = StringHelpers.UrlFormatConverter(fileName); fileName += StringHelpers.GetCode(); var klasoryolu = Server.MapPath("~/Upload/"); var dosyayolu = Server.MapPath("~/Upload/") + fileName + extName; if (!Directory.Exists(klasoryolu)) { Directory.CreateDirectory(klasoryolu); } file.SaveAs(dosyayolu); WebImage img = new WebImage(dosyayolu); img.Resize(250, 250, false); img.AddTextWatermark("Wissen"); img.Save(dosyayolu); model.AvatarPath = "/Upload/" + fileName + extName; } await new ProductRepo().InsertAsync(model); TempData["Message"] = $"{prd.Product.ProductName} isimli ürün başarıyla eklenmiştir"; return(RedirectToAction("Add")); } catch (DbEntityValidationException ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu: {EntityHelpers.ValidationMessage(ex)}", ActionName = "Add", ControllerName = "Product", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu: {ex.Message}", ActionName = "Add", ControllerName = "Product", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }
public AddProductView() { this.InitializeComponent(); _viewModel = DataContext as AddProductViewModel; }
public async Task <ActionResult> AddProduct(AddProductViewModel model) { await CustomAuth.firebase.Child("Products").PostAsync(model); return(View()); }
public ActionResult UrunEkle(AddProductViewModel model, HttpPostedFileBase file) { if (User.Identity.IsAuthenticated) { var kullaniciadi = User.Identity.Name.Split(' '); if (kullaniciadi.Length == 2) { tblKitap kitap = new tblKitap(); if (!ModelState.IsValid) { kitap.KitapID = 0; kitap.ISBNNo = ""; kitap.KapakResmi = ""; kitap.SayfaSayisi = 0; kitap.Aciklama = ""; kitap.Adet = 0; kitap.BasimYili = 0; kitap.Fiyati = 0; kitap.KitapAdi = ""; kitap.StokDurumu = false; kitap.TurID = 0; kitap.YayinEviID = 0; kitap.Yazar = ""; model.tblKitap = kitap; return(View("UrunGuncelleme", model)); } tblKitap kitap2 = db.tblKitap.FirstOrDefault(x => x.ISBNNo == model.ISBNno); try { if (kitap2 != null) { var yenıkıtap = db.tblKitap.Find(kitap2.KitapID); if (yenıkıtap.SilindiMi == true) { yenıkıtap.Adet += Convert.ToInt32(model.Adet); yenıkıtap.SilindiMi = false; yenıkıtap.StokDurumu = true; db.SaveChanges(); ViewBag.Mesaj = 2; } else { yenıkıtap.Adet += Convert.ToInt32(model.Adet); db.SaveChanges(); ViewBag.Mesaj = 2; } } else { tblKitap yeni = new tblKitap(); yeni.Aciklama = model.Aciklama; yeni.Adet = Convert.ToInt32(model.SayfaSayısı); yeni.BasimYili = Convert.ToInt32(model.BasımYili); var para = model.Fiyatı.Split('.'); if (para.Length == 2) { model.Fiyatı = para[0] + "," + para[1]; } yeni.Fiyati = Convert.ToDecimal(model.Fiyatı); yeni.ISBNNo = model.ISBNno; yeni.KitapAdi = model.KitapAdi; yeni.SayfaSayisi = Convert.ToInt32(model.SayfaSayısı); if (Convert.ToInt32(model.Adet) > 0) { yeni.StokDurumu = true; } else { yeni.StokDurumu = false; } yeni.Yazar = model.Yazar; tblKitapTur tur = db.tblKitapTur.FirstOrDefault(x => x.TurAdi == model.TurAdi); if (tur != null) { yeni.TurID = tur.TurID; } tblYayinEvi yayinEvi = db.tblYayinEvi.FirstOrDefault(x => x.YayinEviAdi == model.YayinEvi); if (yayinEvi != null) { yeni.YayinEviID = yayinEvi.YayinEviID; } if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/Content/images/kitaplar"), pic); file.SaveAs(path); yeni.KapakResmi = pic; } yeni.SilindiMi = false; db.tblKitap.Add(yeni); db.SaveChanges(); } return(RedirectToAction("UrunIslemleri")); } catch (Exception) { ViewBag.Mesaj = 3; return(View("UrunGuncelleme", model)); } } } return(HttpNotFound()); }
public virtual ActionResult Create() { AddProductViewModel product = new AddProductViewModel(); return(View(product)); }
public AddProductPage(Product product) { InitializeComponent(); BindingContext = viewModel = new AddProductViewModel(product); }
public IActionResult Add() { AddProductViewModel model = _productWebService.GetAddProductsContent(); return(View($"{ProductsViewFolder}/Add.cshtml", model)); }
public async Task <ActionResult> EditOffer(ProductUpdateForm formDATA) { var ProductDetails = new JavaScriptSerializer().Deserialize <TBL_Products>(formDATA.ProductDetails); UserDetails currentUser = GetCurrentUserDetails(); AddProductViewModel model = new AddProductViewModel(); model.ProductDetails = ProductDetails; if (formDATA.file != null) { model.ProductImages = new List <TBL_ProductImages>(); model.ProductImages.Add(new TBL_ProductImages() { ImageID = CommonSafeConvert.ToInt(formDATA.imgId), ProductID = ProductDetails.ProductID, UpdatedBy = currentUser.UserId, UpdateDate = DateTime.Now, IsActive = true, ProductImage = CommonSafeConvert.ConvertToBytesFromFile(formDATA.file) }); } if (ModelState.IsValid) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(WebAppConfig.GetConfigValue("WebAPIUrl")); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = new CommonAjaxCallToWebAPI().AjaxPost("/api/product/PostEditProduct", model, Convert.ToString(Session["BSWebApiToken"])).Result; // var response = await client.PostAsJsonAsync("/api/product/PostEditProduct", model); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var rslt = await response.Content.ReadAsStringAsync(); var reslt = new JavaScriptSerializer().Deserialize <BSEntityFramework_ResultType>(rslt); if (reslt.Result == BSResult.FailForValidation) { foreach (var valerr in reslt.EntityValidationException) { ModelState.AddModelError("BS Errors", valerr); } } //return reslt; //FillViewDatasForAddShop(); var allErrors = ModelState.Values.SelectMany(v => v.Errors); return(Json(allErrors, JsonRequestBehavior.AllowGet)); } else { return(Json("Failed", JsonRequestBehavior.AllowGet)); } } } return(Json(new { Valid = ModelState.IsValid, UserID = currentUser.UserId, //Errors = GetErrorsFromModelState(), Status = "Validation Failed" })); }
public async Task <IActionResult> Create([Bind("ProductName,ImageUrl,CategoryId,SubCategoryId,BrandId,Id,IP,IsActive,CreatedDateTime,UpdatedDateTime,ModifyBy")] AddProductViewModel product) { string ipAddress = ""; if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0) { ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString(); } product.IP = ipAddress; product.Id = Guid.NewGuid().ToString(); product.UpdatedDateTime = DateTime.Now; product.CreatedDateTime = DateTime.Now; StringBuilder imageUrl = new StringBuilder(); int i = 1; foreach (var file in product.ImageUrl) { if (file.Length > 0) { string ext = Path.GetExtension(file.FileName); using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); //ImagekitResponse response1 = await _imageKitClass.Path("").UploadAsync(fileBytes, product.Id, ext,null);//_documentStorage.UploadDocumentAsync(fileBytes, file.ContentType, product.CategoryId, product.Id+"-"+i+ext); ImagekitResponse response = await _imageKit.Folder(product.CategoryId).isPrivateFile(true).UseUniqueFileName(false).FileName($"{product.Id}{ext}").UploadAsync(fileBytes); //imageUrl.Append(cloudBlockBlob.Uri.AbsoluteUri); //imageUrl.Append(","); } i++; } } if (ModelState.IsValid) { Product addProduct = new Product { Category = product.Category, CategoryId = product.CategoryId, CreatedDateTime = product.CreatedDateTime, Description = product.Description, Id = product.Id, ImageUrl = imageUrl.ToString().TrimEnd(','), IP = product.IP, IsActive = product.IsActive, ModifyBy = product.ModifyBy, ProductName = product.ProductName, SubCategory = product.SubCategory, SubCategoryId = product.SubCategoryId, UpdatedDateTime = product.UpdatedDateTime, BrandId = product.BrandId }; _context.Add(addProduct); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId); ViewData["SubCategoryId"] = new SelectList(_context.SubCategories, "Id", "Id", product.SubCategoryId); ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "BrandName", product.BrandId); return(View(product)); }
public async Task <IActionResult> Edit(string id, [Bind("ProductName,ImageUrl,CategoryId,SubCategoryId,BrandId,Id,IP,IsActive,CreatedDateTime,UpdatedDateTime,ModifyBy")] AddProductViewModel product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Product updateProduct = _context.Products.Find(product.Id); StringBuilder imageUrl = new StringBuilder(); int i = 1; if (product.ImageUrl != null) { foreach (var file in product.ImageUrl) { if (file.Length > 0) { string ext = Path.GetExtension(file.FileName); using (var ms = new MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); string[] purgeURL = updateProduct.ImageUrl != null?updateProduct.ImageUrl.Split(',') : null; //ImagekitResponse response = await _imageKitClass.UploadAsync(fileBytes, product.Id, ext,purgeURL); ImagekitResponse response = await _imageKit.Folder(product.CategoryId).isPrivateFile(true).UseUniqueFileName(false).FileName($"{product.Id}{ext}").UploadAsync(fileBytes); //_documentStorage.UploadDocumentAsync(fileBytes, file.ContentType, product.CategoryId, product.Id+"-"+i+ext); //var cloudBlockBlob = await _documentStorage.UploadDocumentAsync(fileBytes, file.ContentType, product.CategoryId, product.Id + "-" + i + ext); imageUrl.Append(response.URL); imageUrl.Append(","); imageUrl.Append(response.Thumbnail); imageUrl.Append(","); } i++; } } } if (imageUrl.Length > 0) { updateProduct.ImageUrl = imageUrl.ToString().TrimEnd(','); } string ipAddress = ""; if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0) { ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString(); } product.IP = ipAddress; product.UpdatedDateTime = DateTime.Now; updateProduct.CategoryId = product.CategoryId; updateProduct.Description = product.Description; updateProduct.IP = product.IP; updateProduct.IsActive = product.IsActive; updateProduct.ModifyBy = product.ModifyBy; updateProduct.ProductName = product.ProductName; updateProduct.SubCategoryId = product.SubCategoryId; updateProduct.UpdatedDateTime = product.UpdatedDateTime; updateProduct.BrandId = product.BrandId; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId); ViewData["SubCategoryId"] = new SelectList(_context.SubCategories, "Id", "Id", product.SubCategoryId); ViewData["BrandId"] = new SelectList(_context.Brands, "Id", "BrandName", product.BrandId); return(View(product)); }
public async Task ChangeViewModel(AddProductViewModel model) { var categories = await _categoryRepo.GetCategoriesAsync(); model.Categories = new SelectList(categories, "CategoryId", "Name"); }
public AddProduct() { InitializeComponent(); BindingContext = new AddProductViewModel(); }
public async Task <IActionResult> Products() { AddProductViewModel model = new AddProductViewModel(await _repository.SelectAll <Produkt>()); return(View(model)); }
public BaseWebServiceResponse Add(AddProductViewModel model) { var response = new BaseWebServiceResponse(); if (_productService.ProductNameExists(model.ProductName)) { response.Error.Name = "Product Name"; response.Error.Message = "Product Name exists"; return(response); } decimal price; if (!decimal.TryParse(model.Price, out price)) { response.ActionSuccessful = false; response.Error.Name = "Price"; response.Error.Message = "Price must be a decimal value e.g. 100.00"; return(response); } List <IFormFile> listFiles = new List <IFormFile>() { model.Image1, model.Image2, model.Image3, model.Image4, }; bool fileExists = _fileValidationWebService.FileExists(listFiles); if (!fileExists) { response.Error.Name = "Images"; response.Error.Message = "At least one Image must be uploaded."; return(response); } bool filesAreJpg = _fileValidationWebService.IsFileFormatJpg(listFiles); if (!filesAreJpg) { response.Error.Name = "Images"; response.Error.Message = "Files must be jpg file format."; return(response); } //TODO: Refactor this - Mapper or Helper var productDto = mapper.Map <AddProductViewModel, ProductDTO>(model); productDto.Gender = _genderService.GetGenderById(Convert.ToInt32(model.SelectedGender)); productDto.Price = price; productDto.HeroImage = ProductHelper.WriteImageToBytes(model.HeroImage); productDto.Images.Add(new ProductImageDTO() { Image = ProductHelper.WriteImageToBytes(model.Image1) }); productDto.Images.Add(new ProductImageDTO() { Image = ProductHelper.WriteImageToBytes(model.Image2) }); productDto.Images.Add(new ProductImageDTO() { Image = ProductHelper.WriteImageToBytes(model.Image3) }); productDto.Images.Add(new ProductImageDTO() { Image = ProductHelper.WriteImageToBytes(model.Image4) }); productDto.Sizes = JsonConvert.DeserializeObject <List <ProductSizeDTO> >(model.SizesJson); if (!_productService.Add(productDto)) { response.Error.Name = "Add Product"; response.Error.Message = "There was a problem while attempting to add the Product, please try again. If this problem persists, please contact support."; return(response); } response.ActionSuccessful = true; response.SuccessMessage = "Product added successfully!"; return(response); }
public IActionResult EditProduct(AddProductViewModel model) { model.Categories = db.Category.ToList(); if (ModelState.IsValid) { //Show error if (model.MainImageFile != null && !IsImageValid(model.MainImageFile)) { return(View("EditProductView", model)); } if (model.Images != null) { foreach (var image in model.Images) { var valid = IsImageValid(image); if (!valid) { // Show error that only images allowed return(View("EditProductView", model)); } } } var filePath = Path.GetTempFileName(); var imageIds = new List <String>(); if (model.Images != null) { foreach (var formFile in model.Images) { var imageId = UploadImage(formFile, filePath); imageIds.Add(imageId); } } string mainImageId = ""; if (model.MainImageFile != null) { mainImageId = UploadImage(model.MainImageFile, filePath); } var product = db.Product.Find(model.Id); product.Title = model.Title; product.Description = model.Description; product.Price = model.Price; product.CategoryId = model.CategoryId; product.Discount = model.Discount; product.SkuCode = model.SkuCode; product.MainImageId = mainImageId; product.ShortDescription = model.ShortDescription; imageIds.ForEach(id => db.Image.Add( new Image() { Id = id, ProductId = product.Id })); db.SaveChangesAsync(); return(View("EditProductView", model)); } else { return(View("EditProductView", model)); } }
public async Task <RespondModel> AddAsync(AddProductViewModel addProductViewModel) { var product = AutoMapper.Mapper.Map <Product>(addProductViewModel); return(await _repository.InsertAsync(product)); }
public AddNewProductCommand(AddProductViewModel viewModel) { _viewModel = viewModel; }
public ActionResult UrunGuncelleme2(AddProductViewModel model, int id) { if (User.Identity.IsAuthenticated) { var kullaniciadi = User.Identity.Name.Split(' '); if (kullaniciadi.Length == 2) { tblKitap kitap = new tblKitap(); if (id != 0) { model.tblKitap = db.tblKitap.Find(id); } if (!ModelState.IsValid) { return(View("UrunGuncelleme", model)); } else if (id != 0) { tblKitap kitapguncellenecek = db.tblKitap.Find(id); try { kitapguncellenecek.Aciklama = model.Aciklama; kitapguncellenecek.Adet = Convert.ToInt32(model.Adet); kitapguncellenecek.BasimYili = Convert.ToInt32(model.BasımYili); var para = model.Fiyatı.Split('.'); if (para.Length == 2) { model.Fiyatı = para[0] + "," + para[1]; } kitapguncellenecek.Fiyati = Convert.ToDecimal(model.Fiyatı); kitapguncellenecek.ISBNNo = model.ISBNno; kitapguncellenecek.KitapAdi = model.KitapAdi; kitapguncellenecek.SayfaSayisi = Convert.ToInt32(model.SayfaSayısı); if (Convert.ToInt32(model.Adet) > 0) { kitapguncellenecek.StokDurumu = true; } else { kitapguncellenecek.StokDurumu = false; } tblKitapTur tur = db.tblKitapTur.FirstOrDefault(x => x.TurAdi == model.TurAdi); if (tur != null) { kitapguncellenecek.TurID = tur.TurID; } tblYayinEvi yayinEvi = db.tblYayinEvi.FirstOrDefault(x => x.YayinEviAdi == model.YayinEvi); if (yayinEvi != null) { kitapguncellenecek.YayinEviID = yayinEvi.YayinEviID; } db.SaveChanges(); } catch (Exception) { ViewBag.Mesaj = 1; } } return(RedirectToAction("UrunIslemleri", "Admin")); } } return(HttpNotFound()); }
public AddProductView(AddProductViewModel viewModel) { DataContext = viewModel; WindowStartupLocation = WindowStartupLocation.CenterScreen; InitializeComponent(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { AddProductViewModel ViewModel = new AddProductViewModel(e.Parameter as Company); DataContext = ViewModel; }
public IActionResult AddProductResult(AddProductViewModel model) { var productsViewModel = _productsService.AddProduct(model); return(View("ProductsList", productsViewModel)); }
public virtual async Task <ActionResult> AddProduct(AddProductViewModel productModel) { if (!ModelState.IsValid) { ViewData["CategoriesSelectList"] = new MultiSelectList( (await _categoryService.GetAll()) .Union(productModel.Categories.Select(x => new Category { Name = x }), new ProductCategoryComparer()), "Name", "Name", productModel.Categories); return(View(productModel)); } if (productModel.Count <= 0) { productModel.Count = 0; productModel.ProductStatus = ProductStatus.NotAvailable;; } var addedProductImages = productModel.Images .Where(image => image.Id == null) .Select(image => new { image.Url, image.Name, image.ThumbnailUrl }) .ToList(); var deletedProductImages = new List <ProductImage>(); var product = new DomainClasses.Product(); foreach (var productImage in productModel.Images.Where(image => image.Id == null)) { productImage.Url = Url.Content("~/UploadedFiles/ProductImages/" + Path.GetFileName(getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages")))); productImage.ThumbnailUrl = Url.Content("~/UploadedFiles/ProductImages/Thumbs/" + Path.GetFileName(getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages/Thumbs")))); productImage.DeleteUrl = ""; } _mappingEngine.Map(productModel, product); if (productModel.Id.HasValue) { deletedProductImages = (await _productService.EditProduct(product)).ToList(); TempData["message"] = "کالای مورد نظر با موفقیت ویرایش شد"; } else { product.Title = productModel.Name; product.PostedDate = DateTime.Now; product.PostedByUserId = 1; await _productService.AddProduct(product); TempData["message"] = "کالای جدید با موفقیت ثبت شد"; } await _unitOfWork.SaveAllChangesAsync(); foreach (var productImage in addedProductImages) { var path = getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages")); var thumbPath = getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages/Thumbs")); System.IO.File.Move(Server.MapPath("~/Content/tmp/" + Path.GetFileName(productImage.Url)), path); System.IO.File.Move(Server.MapPath("~/Content/tmp/" + Path.GetFileName(productImage.ThumbnailUrl)), thumbPath); } foreach (var productImage in deletedProductImages) { var path = Server.MapPath("~/UploadedFiles/ProductImages/" + productImage.Name); var thumbPath = Server.MapPath("~/UploadedFiles/ProductImages/Thumbs/" + productImage.Name); System.IO.File.Delete(path); System.IO.File.Delete(thumbPath); } if (productModel.Id.HasValue) { LuceneIndex.ClearLuceneIndexRecord(productModel.Id.Value); } //Index the new product lucene.NET LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel { ProductId = product.Id, Description = product.Body.RemoveHtmlTags(), Title = product.Title, ProductStatus = product.ProductStatus.ToString(), Price = product.Prices .OrderByDescending(productPrice => productPrice.Date) .Select(productPrice => productPrice.Price). FirstOrDefault(). ToString(CultureInfo.InvariantCulture), Image = product.Images.OrderBy(image => image.Order) .Select(image => image.ThumbnailUrl) .FirstOrDefault(), SlugUrl = product.SlugUrl, Category = "کالاها" }); return(RedirectToAction(MVC.Product.Admin.ActionNames.Index)); }
public ActionResult NewProduct() { var model = new AddProductViewModel(); return(View(model)); }
public AddProductView() { InitializeComponent(); DataContext = new AddProductViewModel(this); }
public ActionResult SaveNewProduct(AddProductViewModel model) { List <ProductImages> images = new List <ProductImages>(); string folderDate = DateTime.Now.ToString("yyyyMMddHHmmss"); Directory.CreateDirectory(Server.MapPath("~/DynamicContent/ProductImages/Product" + folderDate)); var path = "~/DynamicContent/ProductImages/Product" + folderDate; var pathToSave = "DynamicContent/ProductImages/Product" + folderDate; var imgPath = ""; for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0 && HttpPostedFileBaseExtensions.IsImage(file)) { var fileName = Path.GetFileName(file.FileName); ProductImages fileDetail = new ProductImages() { FileName = fileName, Extension = Path.GetExtension(fileName), FileNameNoExt = Path.GetFileNameWithoutExtension(fileName), FilePath = pathToSave }; images.Add(fileDetail); imgPath = Path.Combine(Server.MapPath(path), fileDetail.FileName); file.SaveAs(imgPath); } } var PdfPathToSave = ""; if (model.document != null && model.document.ContentLength > 0) { Directory.CreateDirectory(Server.MapPath("~/DynamicContent/ProductPDFs/Product" + folderDate)); var PdfPath = Path.Combine(Server.MapPath("~/DynamicContent/ProductPDFs/Product" + folderDate), model.document.FileName); PdfPathToSave = "DynamicContent/ProductPDFs/Product" + folderDate; model.document.SaveAs(PdfPath); } var dbProduct = new Product { DatePublished = DateTime.Now, Images = images, isActive = model.isActive, Name = model.Name, Subtitle = model.Subtitle, Text = model.Text, Price = model.Price, MetaDescription = model.MetaDescription, MetaKeywords = model.MetaKeywords, DocumentPath = PdfPathToSave, DocumentName = model.document.FileName, NumberOfDownloads = 0 }; _unitOfWork.Product.AddProduct(dbProduct); _unitOfWork.Complete(); return(RedirectToAction("Index")); }
public async Task <Guid> Add(AddProductViewModel model) { return(await _productRepository.Add(model)); }
public AddProductPage(AddProductViewModel viewModel) { InitializeComponent(); BindingContext = viewModel; }
public ActionResult AddProduct() { AddProductViewModel addProductVm = this.service.GetAddProductVm(); return(this.View(addProductVm)); }
public IActionResult Add() { var viewModel = new AddProductViewModel(); return(View(viewModel)); }