/// <summary> /// Save the friendship to database. /// </summary> /// <param name="friendship">Friendship model.</param> public void SaveFriendship(FriendshipModel friendship) { ValidateModel(friendship); using (var context = new FriendshipContext()) { var existingModel = context .Objects .FirstOrDefault(model => model.ParentId == friendship.ParentId && model.AcceptorAccountId == friendship.AcceptorAccountId); if (existingModel == null) { context.Objects.Add(friendship); } else { string message = $"Friendship between {existingModel.NavigationParent.Name} and { existingModel.AcceptorAccount.Name } already exists"; throw new InvalidOperationException(message); } context.SaveChanges(); CacheIncomingFriendship(friendship); CacheOutgoingFriendship(friendship); } }
public async Task <bool> SaveAll() { int changes = _context.SaveChanges(); if (changes > 0) { return(true); } else { return(false); } }