public void UpdateTask(Task task) { var updateTask = _context.Tasks.Where(x => x.TaskId == task.TaskId).SingleOrDefault(); updateTask.TaskName = task.TaskName; updateTask.ParentId = task.ParentId; updateTask.Priority = task.Priority; updateTask.StartDate = task.StartDate; updateTask.EndDate = task.EndDate; updateTask.ProjectId = task.ProjectId; updateTask.UserId = task.UserId; _context.MarkAsModified(updateTask); _context.SaveChanges(); }
public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != user.User_ID) { return(BadRequest()); } //db.Entry(user).State = EntityState.Modified; db.MarkAsModified(user); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutProject(int id, ProjectDetailModel projectModal) { if (id != projectModal.Project_Id) { return(BadRequest()); } var project = new Project(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <ProjectDetailModel, Project>(); }); IMapper iMapper = config.CreateMapper(); project = iMapper.Map <ProjectDetailModel, Project>(projectModal); //db.Entry(project).State = EntityState.Modified; db.MarkAsModified(project); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } var changeUser = db.Users.Where(x => x.Project_ID == project.Project_Id).FirstOrDefault(); changeUser.Project_ID = null; try { db.SaveChanges(); } catch (Exception ex) { throw ex; } var user = db.Users.Find(projectModal.User_ID); user.Project_ID = project.Project_Id; try { db.SaveChanges(); } catch (Exception ex) { throw ex; } return(StatusCode(HttpStatusCode.NoContent)); }
public void UpdateUser(User user) { var userModel = _context.Users.Where(x => x.UserId == user.UserId).SingleOrDefault(); if (userModel != null) { userModel.First_Name = user.First_Name; userModel.Last_Name = user.Last_Name; userModel.Employee_Id = user.Employee_Id; //_context.Entry(userModel).State = System.Data.Entity.EntityState.Modified; _context.MarkAsModified(userModel); _context.SaveChanges(); } }
public void UpdateProject(Entities.Project project) { var projectModel = _context.Projects.Where(x => x.ProjectId == project.ProjectId).SingleOrDefault(); if (projectModel != null) { projectModel.Project_Name = project.Project_Name; projectModel.Priority = project.Priority; projectModel.Start_Date = project.Start_Date; projectModel.End_Date = project.End_Date; //_context.Entry(projectModel).State = System.Data.Entity.EntityState.Modified; _context.MarkAsModified(projectModel); _context.SaveChanges(); } }
public IHttpActionResult PutTask(int id, Task task) { db.MarkAsModified(task); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } var changeUser = db.Users.Where(x => x.Task_ID == task.Task_ID).FirstOrDefault(); changeUser.Task_ID = null; try { db.SaveChanges(); } catch (Exception ex) { throw ex; } var user = db.Users.Find(task.User_ID); user.Task_ID = task.Task_ID; try { db.SaveChanges(); } catch (Exception ex) { throw ex; } return(StatusCode(HttpStatusCode.NoContent)); }