public async Task AddTodoAsync(TodoForm form) { if (!IsLoggedIn) { throw new NotLoggedInException(); } await PostAsync($"todo", form); }
public IActionResult Example(TodoForm form) { if (!ModelState.IsValid) { StatusCode(400); return(Json(new { Error = "Model not valid." })); } return(Json(new { Success = "Ok" })); }
public async Task <ActionResult <object> > Update([FromBody] TodoForm form) { try { return(await _todoService.Update(form)); } catch (Exception ex) { return(new ApiResponse(ex.Message)); } }
public async Task <ActionResult <object> > Update(TodoForm form) { try { var todo = await _context.ToDo.FirstOrDefaultAsync(x => x.Id == form.Id); var statusCodeCompleted = await _context.Status .Where(x => x.Code == "COMPLETED") .Select(x => x.Code) .FirstOrDefaultAsync(); if (todo == null) { return(new ApiResponse("Không tìm thấy todo này!!")); } todo.Name = form.Name; todo.StatusCode = form.StatusCode; if (form.StatusCode == statusCodeCompleted) { var subTodoList = await _context.SubTodo.Where(x => x.TodoId == form.Id).ToListAsync(); foreach (var subTodo in subTodoList) { subTodo.StatusCode = statusCodeCompleted; } _context.SubTodo.UpdateRange(subTodoList); } _context.ToDo.Update(todo); await _context.SaveChangesAsync(); return(new ApiResponse()); } catch (Exception ex) { return(new ApiResponse(ex.Message)); } }
public async Task <ActionResult <object> > Create(TodoForm form) { try { var model = new ToDo { Name = form.Name, CreatedAt = DateTime.Now, StatusCode = form.StatusCode }; _context.ToDo.Add(model); await _context.SaveChangesAsync(); return(new ApiResponse()); } catch (Exception ex) { return(new ApiResponse(ex.Message)); } }