public async Task <IActionResult> Documentation() { ApplicationUser usr = await GetCurrentUserAsync(); var id = usr.Id; var store = storedetailsServices.GetAll().Where(x => x.storeid == id).FirstOrDefault(); var model = new storedetaildocumentationviewmodel(); if (store != null) { if (!string.IsNullOrEmpty(store.licPhoto)) { model.licPhotoName = store.licPhoto; } } return(View(model)); }
public async Task <IActionResult> Documentation(storedetaildocumentationviewmodel model) { if (ModelState.IsValid) { ApplicationUser usr = await GetCurrentUserAsync(); var id = usr.Id; // var idd = storedetailsServices.GetAll().Where(x => x.storeid == id).FirstOrDefault().id; var store = storedetailsServices.GetAll().Where(x => x.storeid == id).FirstOrDefault(); if (store == null) { var details = new storedetails { storeid = id, contactpersonname = "", isdeleted = false, }; if (model.licPhoto != null && model.licPhoto.Length > 0) { var uploadDir = @"uploads/storeBannerPhoto"; var fileName = Path.GetFileNameWithoutExtension(model.licPhoto.FileName); var extesion = Path.GetExtension(model.licPhoto.FileName); var webRootPath = _hostingEnvironment.WebRootPath; if (details.licPhoto != null) { var imagePath = webRootPath + details.licPhoto.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); // await model.licPhoto.CopyToAsync(new FileStream(path, FileMode.Create)); FileStream fs = new FileStream(path, FileMode.Create); await model.licPhoto.CopyToAsync(fs); fs.Close(); details.licPhoto = '/' + uploadDir + '/' + fileName; } await storedetailsServices.CreateAsync(details); } else { // storename, radiusid, deliverytimeid, orderMinAmount, packagingCharges, storeBannerPhoto, //address, description, storetim //store.id = idd; var webRootPath = _hostingEnvironment.WebRootPath; if (store.licPhoto != null) { var imagePath = webRootPath + store.licPhoto.ToString().Replace("/", "\\"); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } } var uploadDir = @"uploads/licPhoto"; var fileName = Path.GetFileNameWithoutExtension(model.licPhoto.FileName); var extesion = Path.GetExtension(model.licPhoto.FileName); fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); // await model.licPhoto.CopyToAsync(new FileStream(path, FileMode.Create)); FileStream fs = new FileStream(path, FileMode.Create); await model.licPhoto.CopyToAsync(fs); fs.Close(); store.licPhoto = '/' + uploadDir + '/' + fileName; await storedetailsServices.UpdateAsync(store); } TempData["success"] = "Record Saved Successfully"; return(RedirectToAction("Documentation")); //return RedirectToAction("Index", "Home"); } else { return(View(model)); } }