public ActionResult Index(Profile data, IFormFile Avatar) { if (Avatar != null) { ImageManager AddImage = new ImageManager(_context); AddImage.AddAvatar(Avatar, int.Parse(User.Identity.Name)); data.ImageId = _context.Profiles.Find(data.ID).ImageId; ViewBag.Avatar = _context.Images.FirstOrDefault(imeg => imeg.ID == data.ImageId).Image; } _context.Profiles.Remove(_context.Profiles.Find(data.ID)); _context.Profiles.Add(data); _context.SaveChanges(); ViewBag.Profile = data; return(View(data)); }