public IActionResult GeneralProfile(ProfileViewEmployer fromData) { using (GlobalDBContext _context = new GlobalDBContext()) { if (fromData.UserImage != null && fromData.UserImage.Length > 0) { string uploadFolder = _env.WebRootPath + @"\uploads\UserImage\"; // File of code need to be Tested //string file_Path = HelpersFunctions.StoreFile(uploadFolder, generalProfile.UserImage); string uniqueFileName = Guid.NewGuid().ToString() + "_" + fromData.UserImage.FileName; string filePath = uploadFolder + uniqueFileName; FileStream stream = new FileStream(filePath, FileMode.Create); fromData.UserImage.CopyTo(stream); stream.Dispose(); // Delete previous uploaded Image if (!String.IsNullOrEmpty(_user.UserImage)) { string imagePath = uploadFolder + _user.UserImage; if (System.IO.File.Exists(imagePath)) { // If file found, delete it System.IO.File.Delete(imagePath); Console.WriteLine("File deleted."); } } // if new image is uploaded with other user info _user.AddFromEmployerProfileView(fromData, uniqueFileName); } else { // Adding generalProfile attr to user without image _user.AddFromEmployerProfileView(fromData); } _context.Users.Update(_user); _context.SaveChanges(); fromData.UserImageName = _user.UserImage; // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); //-------------------- END return(View(fromData)); } }
public IActionResult GeneralProfile() { // Display User name on the right-top corner - shows user is logedIN ViewData["LoggeduserName"] = new List <string>() { _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage }; // Geting Dashboard Menu from project/data/DashboardMenuOption.json into ViewData string path = _env.ContentRootPath + @"\Data\DashboardMenuOptions.json"; ViewData["menuItems"] = HelpersFunctions.GetMenuOptionsForUser(_user.UserId, path); //-------------------- END using (GlobalDBContext _context = new GlobalDBContext()) { ProfileViewEmployer userViewModel = new ProfileViewEmployer(_user); return(View(userViewModel)); } }