public async Task <IHttpActionResult> PostTask(Models.Task task) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } task.DateEnd = task.AddBusinessDay(task.DateStart, task.Workload); db.Tasks.Add(task); await db.SaveChangesAsync(); db.Entry(task).Reference(x => x.Employee).Load(); db.Entry(task).Reference(x => x.ProjectManager).Load(); var dto = new TaskDTO() { Id = task.Id, TaskName = task.TaskName, ProjectManagerName = task.ProjectManager.Name, EmployeeName = task.Employee.Name, DateStart = task.DateStart, Workload = task.Workload, DateEnd = task.DateEnd }; return(CreatedAtRoute("DefaultApi", new { id = task.Id }, dto)); }
public ActionResult EditTaskById(Guid id, Guid projectId, [FromBody] Models.DTO.Task taskForEdit) { if (taskForEdit.Id != id && taskForEdit.ProjectId != projectId) { return(BadRequest()); } //if (_context.Projects.Any(e => e.Id == projectForEdit.Id)) //{ // return NotFound(); //} _context.Entry(taskForEdit).State = EntityState.Modified; try { _context.SaveChanges(); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } return(Ok()); }
/**/ /* * NAME: * UpdateProject - update a Project entry in the database * SYNOPSIS: * UpdateProject(Project project) * project --> the updated Project object * DESCRIPTION: * Accesses the database context in order to find and update the Project entry whose projectId attribute * matches the id in the given Project object. The attribute values in the new Project object replaces * the previous attribute values in the database * RETURNS * The object representing the updated project * AUTHOR * Biplab Thapa Magar * DATE * 09/10/2020 * / * /**/ public Project UpdateProject(Project project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } var projectToUpdate = _context.Projects.Find(project.ProjectId); // //make changes to entry _context.Entry(projectToUpdate).CurrentValues.SetValues(project); return(project); }
public ActionResult <Project> Get(int id) { var headerInformation = new HeaderInformation(Request.Headers); var item = _context.Projects.Find(id); if (item == null) { return(NotFound()); } _context.Entry(item) .Collection(project => project.Tasks) .Load(); return(item); }
public string UpdateProject(Project project) { var entity = _context.projects.Find(project.Project_ID); _context.Entry(entity).CurrentValues.SetValues(project); _context.SaveChanges(); return("Project updated successfully."); }
public string UpdateUser(User user) { var entity = _context.users.Find(user.User_ID); _context.Entry(entity).CurrentValues.SetValues(user); _context.SaveChanges(); return("User updated successfully"); }
public ActionResult Edit([Bind(Include = "ID,Username,FirstName,LastName,Password,Email,UserRole")] User user) { if (ModelState.IsValid) { dbContext.Entry(user).State = EntityState.Modified; dbContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Edit([Bind(Include = "ID,Name")] Project project) { if (ModelState.IsValid) { db.Entry(project).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); }
/**/ /* * NAME: * UpdateUser - updates a AppUser entry in the database using the given App User object * SYNOPSIS: * UpdateUser(AppUser user) * user --> the AppUser object with the updated attributes * DESCRIPTION: * Accesses the database context in order to replace the old AppUser entry with the updated one * RETURNS * the updated AppUser entry * AUTHOR * Biplab Thapa Magar * DATE * 09/29/2020 * / * /**/ public AppUser UpdateUser(AppUser user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var userToUpdate = _context.Users.Find(user.Id); _context.Entry(userToUpdate).CurrentValues.SetValues(user); return(user); }
public void DeleteUser(int Id) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Usr = db.Users.First(i => i.UserId == Id); if (Usr != null) { db.Entry(Usr).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } }
public void DeleteProject(int Id) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Prj = db.Projects.First(i => i.ProjectId == Id); if (Prj != null) { db.Entry(Prj).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } }
public void DeleteTask(int Id) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Tsk = db.Tasks.First(i => i.TaskId == Id); //var Tsk = GetById(item.TaskId); if (Tsk != null) { db.Entry(Tsk).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } }
public ActionResult <Project> GetProject(int id) { var headerInformation = new HeaderInformation(Request.Headers); var item = _context.Tasks.Find(id); if (item == null) { return(NotFound()); } _context.Entry(item) .Reference(task => task.Project) .Load(); if (item.Project != null) { return(item.Project); } return(NotFound()); }
public ActionResult <IList <Task> > GetTasks(int id) { var headerInformation = new HeaderInformation(Request.Headers); var item = _context.Users.Find(id); if (item == null) { return(NotFound()); } _context.Entry(item) .Collection(user => user.Tasks) .Load(); if (item.Tasks != null) { return(item.Tasks.ToList()); } return(new List <Task>()); }
public bool UpdateTask(int taskId, Task task) { var entity = _context.tasks.Find(taskId); if (entity == null) { return(false); } _context.Entry(entity).CurrentValues.SetValues(task); _context.SaveChanges(); return(true); }
public bool UpdateProject(int projectId, Project project) { var entity = _context.projects.Find(projectId); if (entity == null) { return(false); } _context.Entry(entity).CurrentValues.SetValues(project); _context.SaveChanges(); return(true); }
public ActionResult ValidateLogin([Bind(Include = "Username,Password")] User user) { if (ModelState.IsValid) { User dbUser = dbContext.Users.ToList() .Where(u => u.Username.Equals(user.Username) && u.Password.Equals(user.Password)) .FirstOrDefault(); if (dbUser == null) { TempData[Constants.NOTICE] = "Invalid username or password! Please try again!"; return(RedirectToAction("Login")); } dbUser.LastLogin = DateTime.UtcNow; ApplicationState.Instance.CurrentUser = dbUser; dbContext.Entry(dbUser).State = System.Data.Entity.EntityState.Modified; dbContext.SaveChanges(); return(RedirectToAction("Activity")); } return(RedirectToAction("Login")); }
public bool UpdateUser(int empId, User user) { var entity = _context.users.Find(empId); if (entity == null) { return(false); } //user.UserId = null; _context.Entry(entity).CurrentValues.SetValues(user); _context.SaveChanges(); return(true); }
public void UpdateProject(int ProjID) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Proj = db.Projects.First(i => i.ProjectId == ProjID); //var Tsk = GetById(item.TaskId); if (Proj != null) { //Proj.TotalTasks += 1; db.Entry(Proj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //db.Entry(Tsk).CurrentValues.SetValues(item); //db.Tasks.AddOrUpdate(item); } }
public string UpdateTask(Task task) { var entity = _context.tasks.Find(task.Task_ID); _context.Entry(entity).CurrentValues.SetValues(task); _context.SaveChanges(); if (task.IsParentTask) { var parentity = _context.parenttasks.Find(task.Parent_ID); parentity.ParentTaskName = task.TaskName; //_context.Entry(parentity).CurrentValues.SetValues(parentity); _context.SaveChanges(); } return("Task updated successfully."); }
public void UpdateUser(User item) { using (ProjectManagerContext db = new ProjectManagerContext()) { var User = db.Users.First(i => i.UserId == item.UserId); //var Tsk = GetById(item.TaskId); if (User != null) { User.FirstName = item.FirstName; User.LastName = item.LastName; User.EmployeeID = item.EmployeeID; db.Entry(User).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //db.Entry(Tsk).CurrentValues.SetValues(item); //db.Tasks.AddOrUpdate(item); } }
public void UpdateProject(Project item) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Proj = db.Projects.First(i => i.ProjectId == item.ProjectId); //var Tsk = GetById(item.TaskId); if (Proj != null) { Proj.ProjectName = item.ProjectName; Proj.Priority = item.Priority; Proj.SDate = item.SDate; Proj.EDate = item.EDate; db.Entry(Proj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //db.Entry(Tsk).CurrentValues.SetValues(item); //db.Tasks.AddOrUpdate(item); } }
public ActionResult EditProject(Guid id, [FromBody] Project projectForEdit) { if (projectForEdit.Id != id) { return(BadRequest()); } _context.Entry(projectForEdit).State = EntityState.Modified; try { _context.SaveChanges(); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } return(Ok()); }
public void UpdateTask(Task item) { using (ProjectManagerContext db = new ProjectManagerContext()) { var Task = db.Tasks.First(i => i.ProjectId == item.ProjectId); //var Tsk = GetById(item.TaskId); if (Task != null) { Task.TaskName = item.TaskName; Task.ParentTask = item.ParentTask; Task.Priority = item.Priority; Task.SDate = item.SDate; Task.EDate = item.EDate; Task.Status = item.Status; Task.TaskEndFlag = item.TaskEndFlag; // Task.ProjectId = item.ProjectId; //Task.UserId = item.UserId; db.Entry(Task).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //db.Entry(Tsk).CurrentValues.SetValues(item); //db.Tasks.AddOrUpdate(item); } }
/**/ /* * NAME: * UpdateTask - updates a task and records the task update too * SYNOPSIS: * UpdateTask(Task task, string updaterId) * task --> the task that is to be updated (it must contain the updated values; taskId must stay the same) * updaterId --> the id of the user who made the update * DESCRIPTION: * Accesses the database context in order to update the task. Simultaneouslyk this function generates a TaskUpdate * entry from the given information, so that the program can keep track of activity * RETURNS * The updated task object * AUTHOR * Biplab Thapa Magar * DATE * 09/06/2020 * / * /**/ public Task UpdateTask(Task task, string updaterId) { if (task == null) { throw new ArgumentNullException(nameof(task)); } var taskToUpdate = _context.Tasks.Find(task.TaskId); //now, for each changed value, store a TaskUpdate record with the updated value //time of task update var timeStamp = DateTime.Now; //for every updateable field in the Task object, if there was a change, then add a TaskUpdate entry //if the name of the task was changed if (task.Name != taskToUpdate.Name) { //add the updated name to the taskUpdate object var taskNameUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskNameUpdate.Name = task.Name; _context.Add(taskNameUpdate); } //if the taskstatus of the task was changed if (task.TaskStatus != taskToUpdate.TaskStatus) { //add the updated TaskStatus to the taskUpdate object var taskStatusUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskStatusUpdate.TaskStatus = task.TaskStatus; _context.Add(taskStatusUpdate); } //if the Urgency of the task was changed if (task.Urgency != taskToUpdate.Urgency) { //add the updated Urgency to the taskUpdate object var taskUrgencyUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskUrgencyUpdate.Urgency = task.Urgency; _context.Add(taskUrgencyUpdate); } //if the TaskTypeId of the task was changed if (task.TaskTypeId != taskToUpdate.TaskTypeId) { //add the updated TaskTypeId to the taskUpdate object var taskTypeUpdate = new TaskUpdate { TaskId = task.TaskId, TimeStamp = timeStamp, UpdaterId = updaterId }; taskTypeUpdate.TaskTypeId = task.TaskTypeId; _context.Add(taskTypeUpdate); } //update the task _context.Entry(taskToUpdate).CurrentValues.SetValues(task); return(task); }
public async Task <ET> LoadCollection <TProperty>(ET entity, Expression <Func <ET, IEnumerable <TProperty> > > propertyExpression) where TProperty : class { await _context.Entry(entity).Collection(propertyExpression).LoadAsync(); return(entity); }