예제 #1
0
        public async Task <ModifyingActionResult <Note> > AddNote(Note note)
        {
            var errors      = new List <string>();
            var userExisted = await _userRepository.UserExistAsync(note.UserId);

            if (!userExisted)
            {
                errors.Add("User with this id does not exist in tabase");
            }
            var result = new ModifyingActionResult <Note>()
            {
                Success = false,
                Errors  = errors,
            };

            if (errors.Count > 0)
            {
                return(result);
            }

            var addedNote = await _noteRepository.AddAsync(note);

            result.Success = true;
            result.Data    = addedNote;
            return(result);
        }
예제 #2
0
        public async Task <ModifyingActionResult <User> > AddUserAsync(string username)
        {
            var errors = new List <string>();

            if (string.IsNullOrWhiteSpace(username))
            {
                errors.Add(UserServiceError.EMPTY_USERNAME_ERROR);
            }
            else if (await GetUserByUsername(username) != default(User))
            {
                errors.Add(UserServiceError.USERNAME_EXISTED_ERROR);
            }
            var result = new ModifyingActionResult <User>()
            {
                Success = false,
                Errors  = errors,
            };

            if (errors.Count > 0)
            {
                return(result);
            }
            var addedUser = await _userRepository.AddAsync(new User()
            {
                Username = username
            });

            result.Success = true;
            result.Data    = addedUser;
            return(result);
        }