public IActionResult Create(SingleDetailViewModel model) { //we want to check on the photo model property is not null string uniqueFileName = null; if (model.Photo != null) { //To get the path of the www folder we are going to use the IHOSTING ENVIROMENT string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Images"); //to prevent upload image twice we use guid uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } SingleDetails user = new SingleDetails(); user.ApplicationUserId = model.Id; user.UserName = model.UserName; user.ImagePhoto = uniqueFileName; _db.Add(user); _db.SaveChanges(); return(RedirectToAction("Index", "SingleDetail")); }
public IActionResult Create() { //I need to sent the login id in this model var logInUserid = _userManager.GetUserId(HttpContext.User); SingleDetailViewModel model = new SingleDetailViewModel(); model.Id = logInUserid; return(View(model)); }
public IActionResult Edit(string id) { var user = _db.SingleDetails.Where(x => x.ApplicationUserId == id).FirstOrDefault(); SingleDetailViewModel model = new SingleDetailViewModel(); //We attach back the data to the view model model.Id = user.ApplicationUserId; model.UserName = user.UserName; //var userid = _userManager.GetUserId(HttpContext.User); //var user = _db.SingleDetails.Where(s => s.ApplicationUserId == userid).SingleOrDefault(); return(View(model)); }
public IActionResult Photo(string id) { //var userid = _userManager.GetUserId(HttpContext.User); //var user = _db.SingleDetails.Where(s => s.ApplicationUserId == userid).FirstOrDefault(); //use view bag SingleDetailViewModel model = new SingleDetailViewModel(); var user = _db.SingleDetails.Where(x => x.ApplicationUserId == id).FirstOrDefault(); model.Id = user.ApplicationUserId; model.UserName = user.UserName; return(View(user.ImagePhoto)); }