public IHttpActionResult PutTodo(int Id, Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (Id != todo.Id) { return(BadRequest()); } Todoes todoData = db.Todoes.Where(row => row.Id == Id).SingleOrDefault(); if (todoData == null) { return(NotFound()); } todoData.Title = todo.Title; todoData.Completed = todo.Completed; db.SubmitChanges(); return(Ok(todoData)); }
public async Task <IActionResult> PostTodoes([FromForm] TodoParameters paramTodoes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Todoes todoAdd = new Todoes(); todoAdd.Descripcion = paramTodoes.descripcion; todoAdd.Estatus = paramTodoes.estatus; todoAdd.Documento = paramTodoes.documento != null ? paramTodoes.documento.FileName : ""; if (todoAdd.Documento.Length > 0) { string timeStamp = DateTime.Now.Ticks.ToString(); using (var fileStream = new FileStream("wwwroot/App_Data/" + timeStamp + "_" + paramTodoes.documento.FileName, FileMode.Create)) { paramTodoes.documento.CopyTo(fileStream); todoAdd.Documento = fileStream.Name; } } _context.Add(todoAdd); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoes", new { id = todoAdd.TodoId }, todoAdd)); }
public void AddTodo(Todoes theTodo) { theTodo.StartDate = DateTime.Now; theTodo.StatusDate = DateTime.Now; theTodo.Id = 0; db.Todoes.Add(theTodo); db.SaveChanges(); }
public ActionResult Index() { Todoes myTodoes = new Todoes(); DataSet ds = new DataSet(); //Get database configuration from app settings - connection string string connectionString = ConfigurationManager.ConnectionStrings["SQLDBConnection"].ToString(); string queryString = "SELECT Id, Description, DueDate FROM Todoes ORDER BY DueDate;"; try { Trace.TraceInformation("get connection"); Trace.TraceInformation(connectionString); using (SqlConnection connection = new SqlConnection(connectionString)) { Trace.TraceInformation("opening connection"); connection.Open(); Trace.TraceInformation("connection made!"); // Create the Command and Parameter objects. SqlCommand command = new SqlCommand(queryString, connection); SqlDataAdapter da = new SqlDataAdapter(command); ds = new DataSet("ToDo"); da.FillSchema(ds, SchemaType.Source, "ToDo"); da.Fill(ds, "ToDo"); } } catch (Exception ex) { Trace.TraceInformation("ToDo FAILED!"); Trace.TraceInformation(ex.Message.ToString()); if (ex.InnerException != null) { Trace.TraceInformation(ex.InnerException.Message.ToString()); } } //Create list of Todoes foreach (DataRow dr in ds.Tables[0].Rows) { myTodoes.toDoes.Add(new Todo { ID = Convert.ToInt32(dr["Id"]), Description = dr["Description"].ToString(), DueDate = (DateTime)dr["DueDate"] }); } return(View(myTodoes)); }
public void EditTodo(int id) { aTodo = todoList.Single(oneTodo => oneTodo.Id == id); if (aTodo == null) { throw new Exception($"Todo item with Id:{id} was not found. Total todos in the list: {todoList.Count()}"); } aTodo.Update(originalTodo); //Keep the original todo here, so if the user cancels his changes - we can revert addOrEdit = "edit"; showModalForm = true; }
public IHttpActionResult DeleteTodo(int Id) { //var todoData = db.Todoes.Where(row => row.Id == Id); // Multiple Todoes todoData = db.Todoes.Where(row => row.Id == Id).SingleOrDefault(); if (todoData == null) { return(NotFound()); } //db.Todoes.DeleteAllOnSubmit(todoData); // Multiple db.Todoes.DeleteOnSubmit(todoData); db.SubmitChanges(); return(Ok(todoData)); }
public IHttpActionResult PostTodo(Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Todoes todoData = new Todoes { Title = todo.Title, Completed = todo.Completed }; db.Todoes.InsertOnSubmit(todoData); db.SubmitChanges(); return(CreatedAtRoute("DefaultApi", new { Id = todoData.Id }, todoData)); }
public void ShowTodoSteps(int id) { Todoes clickedTodo = todoList.Single(oneTodo => oneTodo.Id == id); if (clickedTodo == null) { throw new Exception($"Todo item with Id:{id} was not found. Total todos in the list: {todoList.Count()}"); } clickedTodo.ShowTodoSteps = !clickedTodo.ShowTodoSteps;//toggle its state if (clickedTodo.ShowTodoSteps) { //The user wants to see the todo steps - read them clickedTodo.TodoSteps = getTodoStepsOf(id).ToList(); } else { clickedTodo.TodoSteps.Clear(); } this.StateHasChanged(); }
public async Task <IActionResult> PutTodoes([FromRoute] int id, [FromBody] Todoes todoes) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != todoes.TodoId) { return(BadRequest()); } Todoes currentTodo = _context.Todoes.SingleOrDefault(m => m.TodoId == id); if (currentTodo.Estatus != todoes.Estatus) { try { _context.Entry(currentTodo).State = EntityState.Modified; _context.Entry(currentTodo).Entity.Documento = currentTodo.Documento; _context.Entry(currentTodo).Entity.Descripcion = currentTodo.Descripcion; _context.Entry(currentTodo).Entity.Estatus = todoes.Estatus; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoesExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); } return(NoContent()); }
public void EditTodo(Todoes aTodo) { db.SaveChanges(); }