public ValidationResponse CreateTodo(CreateTodoRequest request) { ValidationResponse response = new ValidationResponse(); if (request == null || string.IsNullOrWhiteSpace(request.Username) || string.IsNullOrWhiteSpace(request.Token)) { response.Error = "Need to login"; return(response); } User user = context.Users.FirstOrDefault(u => u.Name == request.Username && u.Token == request.Token); if (user == null) { response.Error = "Need to login"; return(response); } var todo = new ToDo(); todo.User = user; todo.Text = request.TodoText; context.Entry(todo).State = EntityState.Added; context.SaveChanges(); return(response); }
public RegisterResponse Register(RegisterRequest registerRequest) { RegisterResponse response = new RegisterResponse(); if (string.IsNullOrWhiteSpace(registerRequest.Username)) { response.Error = "Username is empty"; return(response); } if (string.IsNullOrWhiteSpace(registerRequest.Password)) { response.Error = "Password is empty"; return(response); } User user; if (context.Users.Any()) { user = context.Users.FirstOrDefault(p => p.Name.ToLower() == registerRequest.Username.ToLower()); if (user != null) { response.Error = "User already exists"; return(response); } } user = new User(); user.Name = registerRequest.Username; user.Password = registerRequest.Password; user.Token = Guid.NewGuid().ToString(); context.Entry(user).State = EntityState.Added; context.SaveChanges(); response.Token = user.Token; return(response); }
/// <summary> /// DB method to Soft delete(Mark complete) a task /// </summary> /// <param name="toDoID"></param> /// <returns></returns> public long Update(long toDoID) { ToDo todo = _toDoDbContext.todoS.Find(toDoID); if (todo != null) { todo.isDeleted = true; _toDoDbContext.Entry(todo).State = EntityState.Modified; if (_toDoDbContext.SaveChanges() == 1) { return(todo.Id); } } return(0); }
public async Task <IActionResult> PutToDoItem(int id, ToDoItem toDoItem) { if (id != toDoItem.ToDoItemId) { return(BadRequest()); } _context.Entry(toDoItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutToDo([FromRoute] int id, [FromBody] ToDo toDo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != toDo.ToDoId) { return(BadRequest()); } _context.Entry(toDo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IHttpActionResult PutAspNetUser(string id, AspNetUser aspNetUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != aspNetUser.Id) { return(BadRequest()); } db.Entry(aspNetUser).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AspNetUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutToDoItem(int id, ToDoItem toDoItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != toDoItem.ToDoItemID) { return(BadRequest()); } db.Entry(toDoItem).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoItemExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutUser(int id, User user) { if (id != user.UserId) { return(BadRequest()); } _context.Entry(user).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit([Bind(Include = "Id,Name,Description")] ToDoItem toDoItem) { if (ModelState.IsValid) { db.Entry(toDoItem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(toDoItem)); }
public ActionResult Edit([Bind(Include = "ID,Item,Completed")] ToDoItem toDoItem) { if (ModelState.IsValid) { _db.Entry(toDoItem).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(toDoItem)); }
public async Task <ActionResult> Edit([Bind(Include = "ToDoItemID,Title,Status")] ToDoItem toDoItem) { if (ModelState.IsValid) { db.Entry(toDoItem).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(toDoItem)); }
public void Done(int?id) { var task = GetTask(id); if (task == null) { return; } task.IsDone = true; _context.Entry(task).State = EntityState.Modified; _context.SaveChanges(); }
public async Task <IActionResult> Update([FromRoute] int id, [FromBody] ToDoList list) { ToDoList toDoList = await _context.ToDoLists.FindAsync(id); if (toDoList == null) { return(RedirectToAction("Create", list)); } list.ID = id; _context.Entry(toDoList).State = EntityState.Detached; toDoList = list; _context.ToDoLists.Update(toDoList); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Update([FromRoute] long id, [FromBody] ToDoItem item) { ToDoItem todo = await _context.ToDoItems.FindAsync(id); if (todo == null) { return(RedirectToAction("Create", item)); } item.ID = id; _context.Entry(todo).State = EntityState.Detached; todo = item; _context.ToDoItems.Update(todo); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IHttpActionResult> PutTodo(int id, Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != todo.Id) { return(BadRequest()); } if (todo.TodoTask == null) { todo.TodoTask = _todoDal.GetToDoFromId(id).TodoTask; } db.Entry(todo).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult Edit(Item item) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Edit(Category category) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task Update(ToDo toDo) { _context.Entry(toDo).State = EntityState.Modified; await _context.SaveChangesAsync(); }
public virtual void Update(TEntity entity, string modifiedBy = null) { context.Set <TEntity>().Attach(entity); context.Entry(entity).State = EntityState.Modified; }
public DbEntityEntry Entry(object entity) { return(db.Entry(entity)); }
public Item Edit(Item item) { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(item); }
public async Task <int> Update(T entity) { _dbContext.Set <T>().Attach(entity); _dbContext.Entry(entity).State = EntityState.Modified; return(await Save()); }