public ActionResult EditAssignment(int id) { try { // get task assignment info var assignment = db.TaskAssignments.Where(ta => ta.Id == id).FirstOrDefault(); if (assignment == null) { throw new Exception("Unidentified task assignment!!!"); } // create view model AssignTaskViewModel model = new AssignTaskViewModel(); model.Id = assignment.Id; model.EmployeeId = assignment.EmployeeId; model.TaskId = assignment.TaskId; model.StartDate = assignment.StartTime.ToString("dd/MM/yyyy"); model.StartHour = assignment.StartTime.Hour; model.StartMinute = assignment.StartTime.Minute; model.EndDate = assignment.EndTime.ToString("dd/MM/yyyy"); model.EndHour = assignment.EndTime.Hour; model.EndMinute = assignment.EndTime.Minute; model.Note = assignment.Note; return(View(model)); } catch (Exception ex) { return(RedirectToAction("ErrorMessage", "Admin", new RouteValueDictionary( new { message = ex.Message }))); } }
public IActionResult AssignTask(AssignTaskViewModel data) { var task = _context.Task.Find(data.TaskId); var userId = _context.Member.Find(data.MemberId).UserId; task.AssignUserId = userId; task.UpdatedBy = User.Identity.Name; task.UpdatedDate = DateTime.Now; _context.Task.Update(task); _context.SaveChanges(); return(RedirectToAction("Edit", "Task", new { id = data.TaskId })); }
public async Task <IActionResult> AssignTask([FromBody] AssignTaskViewModel assignTaskViewModel) { var taskGroupRecord = dMContext.TaskGroupRecords .Include(tgr => tgr.TaskGroupMemberLinks) .ThenInclude((TaskGroupMemberLink tgml) => tgml.Task) .Include(tgr => tgr.TaskGroup) .ThenInclude(tg => tg.Group) .SingleOrDefault(tgr => tgr.Id == assignTaskViewModel.TaskGroupRecordId); if (taskGroupRecord == null) { return(NotFoundJson()); } if (taskGroupRecord.Finalized) { return(UnauthorizedJson()); } if (!VerifyIsGroupMember(taskGroupRecord.TaskGroup.Group.Id)) { return(UnauthorizedJson()); } var groupMember = dMContext.GroupMembers.SingleOrDefault(gm => gm.Id == assignTaskViewModel.GroupMemberId); if (groupMember == null) { return(NotFoundJson()); } var link = taskGroupRecord.TaskGroupMemberLinks.Where(tgml => tgml.Task.Id == assignTaskViewModel.TaskId).FirstOrDefault(); if (link == null) { return(NotFoundJson()); } link.GroupMember = groupMember; await dMContext.SaveChangesAsync(); return(SucceededJson()); }
public ActionResult AssignTask(int employeeId = 0) { try { // create model AssignTaskViewModel model = new AssignTaskViewModel(); model.EmployeeId = employeeId; model.StartDate = DateTime.Now.ToString("dd/MM/yyyy"); model.StartHour = 7; model.StartMinute = 30; model.EndDate = DateTime.Now.ToString("dd/MM/yyyy"); model.EndHour = 17; model.EndMinute = 0; model.Note = string.Empty; return(View(model)); } catch (Exception ex) { return(RedirectToAction("ErrorMessage", "Admin", new RouteValueDictionary( new { message = ex.Message }))); } }
public ActionResult EditAssignment(AssignTaskViewModel model) { DateTime startTime, endTime; try { // validate model if (ModelState.IsValid == false) { throw new Exception("Fail to update task assignment. Invalid input data!!!"); } if (DateTime.TryParseExact(model.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out startTime) == false) { throw new Exception("Fail to convert string to start date!!!"); } startTime += new TimeSpan(model.StartHour, model.StartMinute, 0); if (DateTime.TryParseExact(model.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out endTime) == false) { throw new Exception("Fail to convert string to end date"); } endTime += new TimeSpan(model.EndHour, model.EndMinute, 0); // employee existed? var employee = db.Employees.Where(e => e.EmployeeId == model.EmployeeId).FirstOrDefault(); if (employee == null) { throw new Exception("Employee is unidentified!!!"); } // task existed? var task = db.Tasks.Where(t => t.TaskId == model.TaskId).FirstOrDefault(); if (task == null) { throw new Exception("Task is unidentified!!!"); } // get task assignment var assignment = db.TaskAssignments.Where(ta => ta.Id == model.Id).FirstOrDefault(); if (assignment == null) { throw new Exception("Unidentified task assignment"); } // update task assignment; assignment.Date = DateTime.Now; assignment.TaskId = task.TaskId; assignment.EmployeeId = employee.EmployeeId; assignment.StartTime = startTime; assignment.EndTime = endTime; assignment.Note = model.Note; db.SaveChanges(); return(RedirectToAction("AssignTask", "Task", new { employeeId = employee.EmployeeId })); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(View(model)); }
public ActionResult AssignTask(AssignTaskViewModel model) { DateTime startTime, endTime; try { // validate input data if (!ModelState.IsValid) { throw new Exception("Invalid task assignment input data!!!"); } if (DateTime.TryParseExact(model.StartDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out startTime) == false) { throw new Exception("Fail to convert string to start date!!!"); } startTime += new TimeSpan(model.StartHour, model.StartMinute, 0); if (DateTime.TryParseExact(model.EndDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out endTime) == false) { throw new Exception("Fail to convert string to end date"); } endTime += new TimeSpan(model.EndHour, model.EndMinute, 0); // check employee/task existed var employee = db.Employees.Where(e => e.EmployeeId == model.EmployeeId).FirstOrDefault(); if (employee == null) { throw new Exception("Employee is unidentified!!!"); } var task = db.Tasks.Where(t => t.TaskId == model.TaskId).FirstOrDefault(); if (task == null) { throw new Exception("Task is unidentified!!!"); } // create new task assignment TaskAssignment ta = new TaskAssignment(); ta.Date = DateTime.Now; ta.TaskId = task.TaskId; ta.EmployeeId = employee.EmployeeId; ta.StartTime = startTime; ta.EndTime = endTime; ta.Note = model.Note; // save task assignment db.TaskAssignments.Add(ta); db.SaveChanges(); return(RedirectToAction("AssignTask", "Task", new { employeeId = employee.EmployeeId })); } catch (Exception ex) { return(RedirectToAction("ErrorMessage", "Admin", new RouteValueDictionary( new { message = ex.Message }))); } }