public async Task <IActionResult> Edit(int id) { var prod = _sliderServices.GetById(id); if (prod == null) { return(NotFound()); } var model = new sliderCreateViewModel() { id = prod.id, // name = prod.name, }; return(View(model)); }
public async Task <IActionResult> Edit(int id) { var prod = _unitofWork.slider.Get(id); if (prod == null) { return(NotFound()); } var model = new sliderCreateViewModel() { id = prod.id, imgname = prod.name, }; return(View(model)); }
public async Task <IActionResult> Edit(sliderCreateViewModel model) { if (ModelState.IsValid) { var storeobj = _sliderServices.GetById(model.id); if (storeobj == null) { return(NotFound()); } storeobj.id = model.id; if (model.name != null && model.name.Length > 0) { var uploadDir = @"uploads/slider"; var fileName = Path.GetFileNameWithoutExtension(model.name.FileName); var extesion = Path.GetExtension(model.name.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (storeobj.name != null) { var imagePath = webRootPath + storeobj.name.ToString().Replace("/", "\\"); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } } fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); FileStream fs = new FileStream(path, FileMode.Create); await model.name.CopyToAsync(fs); fs.Close(); storeobj.name = '/' + uploadDir + '/' + fileName; } await _sliderServices.UpdateAsync(storeobj); TempData["success"] = "Record Updated successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public async Task <IActionResult> Create(sliderCreateViewModel model) { if (ModelState.IsValid) { var store = new slider { id = model.id, isdeleted = false , isactive = false }; if (model.name != null && model.name.Length > 0) { var uploadDir = @"uploads/slider"; var fileName = Path.GetFileNameWithoutExtension(model.name.FileName); var extesion = Path.GetExtension(model.name.FileName); var webRootPath = _hostingEnvironment.WebRootPath; fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); FileStream fs = new FileStream(path, FileMode.Create); await model.name.CopyToAsync(fs); fs.Close(); store.name = '/' + uploadDir + '/' + fileName; } await _sliderServices.CreateAsync(store); TempData["success"] = "Record Saved successfully"; return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public async Task <IActionResult> Create() { var model = new sliderCreateViewModel(); return(View(model)); }