public async Task <ActionResult> UpdateProfile(ProfileViewModel profileModel) { int currentUser = personRepository.GetIdByUserIdentityEmail((string)User.Identity.Name); Person personToUpdate = personRepository.GetPersonById(currentUser); personToUpdate.FirstName = profileModel.FirstName; personToUpdate.LastName = profileModel.LastName; personToUpdate.Description = profileModel.Description; personToUpdate.AccountHidden = profileModel.AccountHidden; if (ModelState.IsValid) { try { _context.Update(personToUpdate); await _context.SaveChangesAsync(); } catch (Exception) { TempData["ProcessMessage"] = "Could not update profile"; return(PartialView("Exception")); } } return(RedirectToAction("MyProfile")); }
public ActionResult AcceptRequest(int senderId) { int receiverId = personRepository.GetIdByUserIdentityEmail(User.Identity.Name); List <FriendRequest> requests = requestRepository.GetAllRequestsSentToUser(receiverId); foreach (FriendRequest fr in requests) //Loopar genom alla vänförfrågningar användaren har fått { if (fr.SenderId == senderId && fr.ReceiverId == receiverId) //Kontrollerar att sändare och mottagare stämmer { fr.Accepted = true; try { _context.Update(fr); _context.SaveChanges(); } catch (Exception) { TempData["ProcessMessage"] = "Could not update profile picture, please try again"; return(PartialView("Exception")); } } } return(RedirectToAction("Profile", "Person", new { id = senderId })); }
public async Task <IActionResult> Edit(int id, MovieDetails movieDetails, List <IFormFile> Image) { if (id != movieDetails.Id) { return(NotFound()); } if (ModelState.IsValid) { try { foreach (var item in Image) { if (item.Length > 0) { using var stream = new MemoryStream(); await item.CopyToAsync(stream); movieDetails.Image = stream.ToArray(); } } _context.Update(movieDetails); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieDetailsExists(movieDetails.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(movieDetails)); }
public void Update <T>(ref T entity) where T : class { _context.Update(entity); }