public bool UpdateSheet(string username, string charactername, Dto.CharacterSheet sheet) { var user = db.Users.Include(u => u.CharacterSheets) .ThenInclude(s => s.FeatureSkills) .Include(u => u.CharacterSheets) .ThenInclude(s => s.Spells) .Include(u => u.CharacterSheets) .ThenInclude(s => s.Weapons).FirstOrDefault(u => u.UserName == username); if (user == null) { return(false); } var entitysheet = mapper.Map <Entities.CharacterSheet>(sheet); var updatesheet = user.CharacterSheets.FirstOrDefault(cs => RemoveWhitespace(cs.CharacterName.ToLower()) == RemoveWhitespace(charactername.ToLower())); if (updatesheet == null) { return(false); } user.CharacterSheets.Remove(updatesheet); user.CharacterSheets.Add(entitysheet); db.SaveChanges(); return(true); }
public ApplicationUserHeader UpdateUser(string username, ApplicationUserHeader usernew) { var user = db.Users.Include(u => u.Friends).ThenInclude(u => u.Friend2).FirstOrDefault(u => u.UserName == username); if (user == null) { return(null); } user.Email = usernew.Email; user.FirstName = usernew.FirstName; user.LastName = usernew.LastName; user.FriendRequest = usernew.FriendRequest; var newfriends = usernew.Friends.Except(user.Friends.Select(u => u.Friend2.UserName)); foreach (var f in newfriends) { var friend = db.Users.FirstOrDefault(u => u.UserName == f); if (friend != null) { user.Friends.Add(new UserFriend { Friend2 = friend }); } } db.SaveChanges(); return(FindUserByName(username)); }