public IActionResult UpdateHomeSlider(int?id, HomeSliderViewModel viewmodel) { if (id == null) { return(NotFound()); } if (ModelState.IsValid) { try { if (viewmodel.Upload != null) { string upload = Path.Combine(_hosting.WebRootPath, @"image"); string fullpath = Path.Combine(upload, viewmodel.Upload.FileName); viewmodel.Upload.CopyTo(new FileStream(fullpath, FileMode.Create)); viewmodel.Image = viewmodel.Upload.FileName; } var homeslider = new HomeSlider { Id = viewmodel.Id, Image = viewmodel.Image }; _context.Entry(homeslider).State = EntityState.Modified; _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(HomeSliderIndex))); } return(View(viewmodel)); }
public ActionResult AddEditHomeSlider(HomeSliderViewModel model, HttpPostedFileBase file) { var res = AutoMapper.Mapper.Map <HomeSliderViewModel, HomeSlider>(model); if (file != null) { res.ImageURL = UploadFileOnServer(HomeSliderImagePath, file); } var isSuccess = _sliderService.AddOrUpdateHomeSlider(res); return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(HomeSliderViewModel homeSliderViewModel, HttpPostedFileBase files, string submit) { if (ModelState.IsValid) { if (homeSliderViewModel != null && submit == "Save") { homeSliderViewModel.DateCreated = homeSliderViewModel.DateCreated; homeSliderViewModel.DateModified = DateTime.UtcNow; if (files != null) { // Delete exiting file // System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Category/"), serviceViewModel.Image)); // Save new file var fileName = Path.GetFileName(files.FileName); var path = Path.Combine(Server.MapPath("~/UploadFiles/Slider/"), fileName); files.SaveAs(path); homeSliderViewModel.SlideImage = fileName; } var sliderImage = Mapper.Map <HomeSliderViewModel, HomeSlider>(homeSliderViewModel); _slider.Edit(sliderImage); AddMessage(this, "", "Record has been modified Successfully", MessageType.Success); return(RedirectToAction("Index", "HomeSlider")); } if (homeSliderViewModel != null && submit == "SaveAndContinue") { homeSliderViewModel.DateCreated = homeSliderViewModel.DateCreated; homeSliderViewModel.DateModified = DateTime.UtcNow; if (files != null) { // Delete exiting file // System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Category/"), serviceViewModel.Image)); // Save new file var fileName = Path.GetFileName(files.FileName); var path = Path.Combine(Server.MapPath("~/UploadFiles/Offer/"), fileName); files.SaveAs(path); homeSliderViewModel.SlideImage = fileName; } var sliderImage = Mapper.Map <HomeSliderViewModel, HomeSlider>(homeSliderViewModel); _slider.Edit(sliderImage); var id = sliderImage.Id; AddMessage(this, "", "Record has been modified successfully", MessageType.Success); return(RedirectToAction("Edit", new { id = id })); } } return(View(homeSliderViewModel)); }
public async Task <IActionResult> Create([Bind("Id,Media,MediaType")] HomeSliderViewModel homeSliderViewModel) { if (ModelState.IsValid) { string filename = Guid.NewGuid().ToString().Substring(4) + homeSliderViewModel.Media.FileName; UploadFile(homeSliderViewModel.Media, filename); HomeSlider homeSlider = new HomeSlider { Media = filename, MediaType = homeSliderViewModel.MediaType }; _context.Add(homeSlider); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homeSliderViewModel)); }
public ActionResult Create(HomeSliderViewModel homeSliderViewModel, IEnumerable <HttpPostedFileBase> files, string submit) { if (ModelState.IsValid) { if (homeSliderViewModel != null && submit == "Save") { homeSliderViewModel.DateCreated = DateTime.UtcNow; homeSliderViewModel.DateModified = DateTime.UtcNow; foreach (var file in files) { //Some browsers send file names with a full path. You only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/UploadFiles/Slider/"), fileName); homeSliderViewModel.SlideImage = fileName; file.SaveAs(destinationPath); } var sliderImage = Mapper.Map <HomeSliderViewModel, HomeSlider>(homeSliderViewModel); _slider.Add(sliderImage); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); return(RedirectToAction("Index", "HomeSlider")); } if (homeSliderViewModel != null && submit == "SaveAndContinue") { homeSliderViewModel.DateCreated = DateTime.UtcNow; homeSliderViewModel.DateModified = DateTime.UtcNow; foreach (var file in files) { //Some browsers send file names with a full path. You only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/UploadFiles/Slider/"), fileName); homeSliderViewModel.SlideImage = fileName; file.SaveAs(destinationPath); } var sliderImage = Mapper.Map <HomeSliderViewModel, HomeSlider>(homeSliderViewModel); _slider.Add(sliderImage); AddMessage(this, "", "Record has Added Successfully", MessageType.Success); ModelState.Clear(); return(View()); } } return(View(homeSliderViewModel)); }
// GET: HomeSliders/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var homeSlider = await _context.HomeSlider.FindAsync(id); HomeSliderViewModel model = new HomeSliderViewModel { Id = homeSlider.Id, MediaType = homeSlider.MediaType }; if (homeSlider == null) { return(NotFound()); } return(View(model)); }
public IActionResult EditHomeSlider(int?id) { if (id == null) { return(NotFound()); } var slid = _context.HomeSliders.Single(s => s.Id == id); if (slid == null) { return(NotFound()); } HomeSliderViewModel slidviewmodel = new HomeSliderViewModel { Image = slid.Image }; return(View(slidviewmodel)); }
public IActionResult CreateHomeSlider(HomeSliderViewModel model) { if (ModelState.IsValid) { if (model.Upload != null) { string upload = Path.Combine(_hosting.WebRootPath, @"image"); string fullpath = Path.Combine(upload, model.Upload.FileName); model.Upload.CopyTo(new FileStream(fullpath, FileMode.Create)); } HomeSlider slider = new HomeSlider { Image = model.Upload.FileName }; _context.HomeSliders.Add(slider); _context.SaveChanges(); return(RedirectToAction(nameof(HomeSliderIndex))); } return(View(model)); }
public ActionResult GetHomeSlider(int?Id) { HomeSliderViewModel model; if (Id.HasValue) { var res = _sliderService.GetHomeSlider(Id.Value); model = AutoMapper.Mapper.Map <HomeSlider, HomeSliderViewModel>(res); } else { model = new HomeSliderViewModel(); } var productList = _productService.GetProductList(); // productList = productList.Where(t => t.AssocitedID == Convert.ToInt32(Session["UserSessionIDs"])).ToList(); var result = AutoMapper.Mapper.Map <IEnumerable <ProductEntity>, List <ProductDropdownListViewModel> >(productList); model.Products = result; return(PartialView("AddEditHomeSlider", model)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Media,MediaType")] HomeSliderViewModel homeSliderViewModel) { if (ModelState.IsValid) { var row = _context.HomeSlider.Where(x => x.Id == id).FirstOrDefault(); if (homeSliderViewModel.Media != null) { string filename = Guid.NewGuid().ToString().Substring(4) + homeSliderViewModel.Media.FileName; UploadFile(homeSliderViewModel.Media, filename); row.Media = filename; } else { row.Media = row.Media; } row.MediaType = homeSliderViewModel.MediaType; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homeSliderViewModel)); }
public ActionResult Create(HomeSliderViewModel homeSliderViewModel) { homeSliderViewModel.ShowHideImage = false; return(View(homeSliderViewModel)); }