public async Task <FriendVm> AddFriendAsync(FriendVm friend) { var result = await _friendService.AddFriendAsync(friend).ConfigureAwait(false); _cache.Remove(nameof(GetAllFriendsAsync)); return(result); }
public static Friend Extend(this Friend original, FriendVm friend) => new Friend { Id = original.Id, ExportId = friend.Id, Name = friend.Name, Url = friend.Url, Description = friend.Description };
public async Task <FriendVm> UpdateFriendAsync(FriendVm friend) { var result = await _friendService.UpdateFriendAsync(friend).ConfigureAwait(false); _cache.Remove(nameof(GetAllFriendsAsync)); if (_cache.TryGetValue <List <AutocompleteRow> >(nameof(GetAllFriendsAsync), out var friends)) { friends.ForEach(x => _cache.Remove($"{nameof(GetFriendAsync)}_{x.Id}")); } return(result); }
public async Task <FriendVm> UpdateFriendAsync(FriendVm friend) { friend.EnsureIsValid(); var original = await _friendProvider.GetFriendOrDefaultAsync(friend.Id).ConfigureAwait(false); if (original == null) { throw new FormatException($"{nameof(friend.Id)} \"{friend.Id}\" нет в базе"); } original.Name = friend.Name; original.Url = friend.Url; original.Description = friend.Description; await _unitOfWork.SaveChangesAsync(); return(original.ToVm()); }
public async Task <FriendVm> AddFriendAsync(FriendVm friend) { friend.EnsureIsValid(); var original = await _friendProvider.GetFriendOrDefaultAsync(friend.Id).ConfigureAwait(false); if (original != null) { throw new FormatException($"Данный {nameof(friend.Id)} \"{friend.Id}\" уже занят"); } var entity = new Friend { ExportId = friend.Id }.Extend(friend); var res = await _friendProvider.SaveFriendAsync(entity).ConfigureAwait(false); return(res.ToVm()); }
public static FriendVm EnsureIsValid(this FriendVm friend) { // todo: implement full validation if (string.IsNullOrWhiteSpace(friend.Name)) { throw new FormatException(nameof(friend.Name)); } if (string.IsNullOrWhiteSpace(friend.Url)) { throw new FormatException(nameof(friend.Url)); } if (string.IsNullOrWhiteSpace(friend.Description)) { throw new FormatException(nameof(friend.Description)); } return(friend); }
public Task <FriendVm> UpdateFriend([FromBody] FriendVm friend) => _friendService.UpdateFriendAsync(friend);
public Task <FriendVm> AddFriend([FromBody] FriendVm friend) => _friendService.AddFriendAsync(friend);