Esempio n. 1
0
        public async Task <FriendVm> AddFriendAsync(FriendVm friend)
        {
            var result = await _friendService.AddFriendAsync(friend).ConfigureAwait(false);

            _cache.Remove(nameof(GetAllFriendsAsync));

            return(result);
        }
Esempio n. 2
0
 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
 };
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 public Task <FriendVm> UpdateFriend([FromBody] FriendVm friend)
 => _friendService.UpdateFriendAsync(friend);
Esempio n. 8
0
 public Task <FriendVm> AddFriend([FromBody] FriendVm friend)
 => _friendService.AddFriendAsync(friend);