public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,ShortDescription,Image,UrlRus,CategoryId")] SubcategoriesModel subcategoriesModel, IFormFile imageFile) { if (id != subcategoriesModel.Id) { return(NotFound()); } if (imageFile != null || subcategoriesModel.Image == null) { subcategoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { try { _context.Update(subcategoriesModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubcategoriesModelExists(subcategoriesModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Title", subcategoriesModel.CategoryId); return(View(subcategoriesModel)); }
public IActionResult Create(ToyViewModel model) { if (ModelState.IsValid) { model.Toy.Producer = _producerRepository.GetProducerByID(model.Producer); model.Toy.Category = _categoryRepository.GetCategoryById(model.Category); _toyRepository.AddToy(model.Toy); if (model.Images != null) { var helper = new ImageHelper(_environment); foreach (var image in model.Images) { var imageName = helper.AddImage(image); var gallery = new Gallery() { FileName = imageName, Toy = model.Toy }; _galleryRepository.AddImage(gallery); } } _toyRepository.Save(); return(RedirectToAction("Index")); } else { model.Categories = FormHelper.GetFormCategories(_context.Categories.ToArray()); model.Producers = FormHelper.GetFormProducers(_context.Producers.ToArray()); } return(View(model)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,ShortDescription,Image,UrlRus")] CategoriesModel categoriesModel, IFormFile imageFile) { if (id != categoriesModel.Id) { return(NotFound()); } if (imageFile != null) { categoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { try { _context.Update(categoriesModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesModelExists(categoriesModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(categoriesModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,ShortDescription,Image,Price,Discount,UrlRus,SpecialDescription,NumberOfOrders,IndexOnPage,DateIn,DateOut,Route,IsHot,IsTour,IsBustour,IsCruise,SubcategoryId")] ToursModel toursModel, IFormFile imageFile) { if (id != toursModel.Id) { return(NotFound()); } if (imageFile != null) { toursModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { try { _context.Update(toursModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToursModelExists(toursModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["SubcategoryId"] = new SelectList(_context.Subcategories, "Id", "Id", toursModel.SubcategoryId); return(View(toursModel)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,ShortDescription,Image,UrlRus")] CategoriesModel categoriesModel, IFormFile imageFile) { if (imageFile != null) { categoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { _context.Add(categoriesModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoriesModel)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,ShortDescription,Image,UrlRus,CategoryId")] SubcategoriesModel subcategoriesModel, IFormFile imageFile) { if (imageFile != null) { subcategoriesModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { _context.Add(subcategoriesModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Title", subcategoriesModel.CategoryId); return(View(subcategoriesModel)); }
public async Task <IActionResult> Create([Bind("Id,Title,Description,ShortDescription,Image,Price,Discount,UrlRus,SpecialDescription,NumberOfOrders,IndexOnPage,DateIn,DateOut,Route,IsHot,IsTour,IsBustour,IsCruise,SubcategoryId")] ToursModel toursModel, IFormFile imageFile) { if (imageFile != null) { toursModel.Image = ImageHelper.AddImage(_appEnvironment, imageFile); } if (ModelState.IsValid) { _context.Add(toursModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["SubcategoryId"] = new SelectList(_context.Subcategories, "Id", "Title", toursModel.SubcategoryId); return(View(toursModel)); }
public IActionResult Edit(int id, ToyViewModel model) { if (id != model.Toy.ToyID) { return(NotFound()); } if (ModelState.IsValid) { model.Toy.Producer = _producerRepository.GetProducerByID(model.Producer); model.Toy.Category = _categoryRepository.GetCategoryById(model.Category); model.Toy.Condition = (Condition)model.Condition; _context.Update(model.Toy); if (model.Images != null) { var helper = new ImageHelper(_environment); foreach (var image in model.Images) { var imageName = helper.AddImage(image); var gallery = new Gallery() { FileName = imageName, Toy = model.Toy }; _galleryRepository.AddImage(gallery); } } _toyRepository.Save(); return(RedirectToAction("Index")); } return(View(model)); }