public async Task <ToDoItemDetail> CreateAsync(ToDoItemDetail item) { var plan = await _db.Plans.FindAsync(item.PlanId); if (plan == null) { throw new NotFoundException($"Plan with the {item.PlanId} couldn't be found"); } var todoItem = new ToDoItem { EstimatedDate = item.EstimationDate, CreatedDate = DateTime.UtcNow, Description = item.Description, Id = Guid.NewGuid().ToString(), IsDeleted = false, IsDone = false, Plan = plan, UserId = _identity.UserId, ModifiedDate = DateTime.UtcNow, }; await _db.ToDoItems.AddAsync(todoItem); await _db.SaveChangesAsync(); return(todoItem.ToToDoItemDetail()); }
public async Task <ToDoItemDetail> MarkAsDone(ToDoItemDetail todoItem) { todoItem.ModifiedDate = DateTime.Now; todoItem.IsDone = true; await _collection.ReplaceOneAsync(items => items.Id == todoItem.Id, todoItem); return(todoItem); }
public async Task <ToDoItemDetail> AddNew(ToDoItemDetail todoItem) { todoItem.Id = Guid.NewGuid().ToString(); todoItem.ModifiedDate = todoItem.CreatedDate = DateTime.Now; await _collection.InsertOneAsync(todoItem); return(todoItem); }
public async Task <ToDoItemDetail> EditAsync(ToDoItemDetail model) { var item = await _db.ToDoItems.FindAsync(model.Id); if (item == null) { throw new NotFoundException($"ToDo with the {model.Id} couldn't be found"); } item.Description = model.Description; item.AchievedDate = model.AchievedDate; item.ModifiedDate = DateTime.UtcNow; item.IsDone = model.IsDone; await _db.SaveChangesAsync(); return(item.ToToDoItemDetail()); }
public async Task <IOperationResponse <ToDoItemDetail> > UpdateItemAsync(ToDoItemDetail model, string userId) { var item = await _itemsRepo.GetByIdAsync(model.Id); if (item == null) { return(NotFound <ToDoItemDetail>("Item not found")); } item.Description = model.Descrption; item.Category = model.Category; item.ModificationDate = DateTime.UtcNow; item.Points = model.Points; item.Quality = model.Quality; await _itemsRepo.CommitChangesAsync(); return(Success("Item updated successfully!", model)); }
public async Task <IOperationResponse <ToDoItemDetail> > CreateItemAsync(ToDoItemDetail item, string userId) { var todo = new ToDoItem { Id = Guid.NewGuid().ToString(), Category = item.Category, Description = item.Descrption, CreationDate = DateTime.UtcNow, ModificationDate = DateTime.UtcNow, Points = item.Points, Quality = item.Quality, UserId = userId, TaskDate = item.TaskDate.Value.ToUniversalTime(), }; await _itemsRepo.InsertItemAsync(todo); await _itemsRepo.CommitChangesAsync(); item.Id = todo.Id; item.CreationDate = todo.CreationDate; return(Success("Item added successfully", item)); }
public async Task <IActionResult> Put(ToDoItemDetail item) { var result = await _itemsService.UpdateItemAsync(item, UserId); return(Ok(result.Content)); }
public async Task <ToDoItemDetail> MarkAsDone([FromBody] ToDoItemDetail todoItem) { return(await this.repository.MarkAsDone(todoItem)); }
public async Task <ToDoItemDetail> AddNew([FromBody] ToDoItemDetail todoItem) { return(await this.repository.AddNew(todoItem)); }
public async Task <IActionResult> Put([FromBody] ToDoItemDetail model) { var result = await _todos.EditAsync(model); return(Ok(new ApiResponse <ToDoItemDetail>(result, "ToDo edited successfully"))); }