public async Task <IActionResult> EditCoverPicture(int id, EVMCoverPicture employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { string FileNameProfile = UploadCP(employee); Employee vm = new Employee { Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, Age = employee.Age, GitHubLink = employee.GitHubLink, CurrentPosition = employee.CurrentPosition, WantedPosition = employee.WantedPosition, Description = employee.Description, Location = employee.Location, PhoneNumber = employee.PhoneNumber, Mail = employee.Mail, Password = employee.Password, Skills = employee.Skills, ProfilePicutre = employee.ProfileImage, CV = employee.CVFile, CoverLetter = employee.CoverLetterFile, CoverPhoto = FileNameProfile, }; _context.Update(vm); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("")); } AppUser user = await userManager.GetUserAsync(User); if (id != user.EmployeeId) { return(RedirectToAction("AccessDenied", "Account", null)); } return(View(employee)); }
//Za Cover photo public async Task <IActionResult> EditCoverPicture(int?id) { if (id == null) { AppUser curruser = await userManager.GetUserAsync(User); if (curruser.EmployeeId != null) { return(RedirectToAction(nameof(Employee), new { id = curruser.EmployeeId })); } else { return(NotFound()); } } var employee = await _context.Employee.FindAsync(id); if (employee == null) { return(NotFound()); } EVMCoverPicture vm = new EVMCoverPicture { Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, Age = employee.Age, GitHubLink = employee.GitHubLink, CurrentPosition = employee.CurrentPosition, WantedPosition = employee.WantedPosition, Description = employee.Description, Location = employee.Location, PhoneNumber = employee.PhoneNumber, Mail = employee.Mail, Password = employee.Password, Skills = employee.Skills, CVFile = employee.CV, CoverLetterFile = employee.CoverLetter, ProfileImage = employee.ProfilePicutre, }; AppUser user = await userManager.GetUserAsync(User); if (id != user.EmployeeId) { return(RedirectToAction("AccessDenied", "Account", null)); } return(View(vm)); }
public string UploadCP(EVMCoverPicture model) { string uniqueFileName = null; if (model.CoverImage != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images"); uniqueFileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(model.CoverImage.FileName); string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.CoverImage.CopyTo(fileStream); } } return(uniqueFileName); }