public async Task <OperationResult <TaskModel> > MarkTaskAsOpenedAsync(int taskId) { var taskModel = await _taskModelDbOperations.GetAsync(taskId); if (taskModel == null) { return(OperationResult <TaskModel> .NotFound()); } taskModel.MarkAsOpened(); await _taskModelDbOperations.UpdateAsync(taskModel); return(OperationResult <TaskModel> .Ok()); }
public async Task <OperationResult <CommentModel> > UpdateCommentAsync(int commentId, string content) { var comment = await _commentModelDbOperations.GetAsync(commentId); if (comment == null) { return(OperationResult <CommentModel> .NotFound()); } comment.Content = content; await _commentModelDbOperations.UpdateAsync(comment); return(OperationResult <CommentModel> .Ok()); }
async Task <T> IDBInterface.CreateAsync <T>(ToDoEntity todo) { if ((await _userDbOperations.GetAllAsync(e => e.UserId == todo.UserId && e.Title == todo.Title)).Any()) { throw new AppException("ToDo Item with Title \"" + todo.Title + "\" is already taken"); } try { await _userDbOperations.CreateAsync(todo).ConfigureAwait(false); } catch (Exception e) { Console.WriteLine(e); throw; } // Get the newly added ToDo var result = await _userDbOperations.GetAsync(e => e.UserId == todo.UserId && e.Title == todo.Title).ConfigureAwait(false); return(result as T); }
public async Task <User> Authenticate(string userId, string password) { if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(password)) { return(null); } var user = await _userDbOperations.GetAsync(e => e.UserId == userId).ConfigureAwait(false); // check if userId exists if (user == null) { return(null); } // check if password is correct if (!_passwordHashService.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt)) { return(null); } // authentication successful return(user); }
public async Task <OperationResult <ProjectModel> > RenameAsync(int projectId, string name) { var projectModel = await _projectModelDbOperations.GetAsync(projectId); if (projectModel == null) { return(OperationResult <ProjectModel> .NotFound()); } projectModel.Rename(name); var validationResult = await _projectModelValidator.ValidateAsync(projectModel); if (!validationResult.IsValid) { return(ValidationHelper.GetValidationFailedOperationResult <ProjectModel>(validationResult)); } await _projectModelDbOperations.UpdateAsync(projectModel); return(OperationResult <ProjectModel> .Ok()); }