// GET: Activity/Edit/{id} public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bool isSuperAdmin = User.IsInAnyRoles("SuperAdmin"); var organisationId = UserOrganisationId; var centres = NidanBusinessService.RetrieveCentres(organisationId, e => isSuperAdmin || e.CentreId == UserCentreId); var activityAssigneeGroups = NidanBusinessService.RetrieveActivityAssigneeGroups(organisationId, e => isSuperAdmin || e.CentreId == UserCentreId).Items.ToList(); var projects = NidanBusinessService.RetrieveProjects(organisationId, e => e.CentreId == UserCentreId).Items.ToList(); var activityTypes = NidanBusinessService.RetrieveActivityTypes(organisationId, e => true).Items.ToList(); var taskStates = NidanBusinessService.RetrieveTaskStates(organisationId, e => true).Items.ToList(); var activity = NidanBusinessService.RetrieveActivity(organisationId, id.Value, e => true); if (activity == null) { return(HttpNotFound()); } var viewModel = new ActivityViewModel { Centres = new SelectList(centres, "CentreId", "Name"), ActivityAssigneeGroups = new SelectList(activityAssigneeGroups, "ActivityAssigneeGroupId", "Name"), Projects = new SelectList(projects, "ProjectId", "Name"), TaskStates = new SelectList(taskStates, "TaskStateId", "Name"), ActivityTypes = new SelectList(activityTypes, "ActivityTypeId", "Name"), Activity = activity }; viewModel.HoursList = new SelectList(viewModel.HoursType, "Id", "Name"); viewModel.MinutesList = new SelectList(viewModel.MinutesType, "Id", "Name"); return(View(viewModel)); }
// GET: ActivityTask/Edit/{id} public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bool isSuperAdmin = User.IsInAnyRoles("SuperAdmin"); var organisationId = UserOrganisationId; var centreId = UserCentreId; var centres = isSuperAdmin || centreId == 7 ? NidanBusinessService.RetrieveCentres(organisationId, e => true) : NidanBusinessService.RetrieveCentres(organisationId, e => e.CentreId == centreId); var activityTask = NidanBusinessService.RetrieveActivityTask(organisationId, id.Value, e => true); if (activityTask == null) { return(HttpNotFound()); } var activityTaskDataGrid = NidanBusinessService.RetrieveActivityTaskDataGrids(organisationId, e => e.ActivityTaskId == activityTask.ActivityTaskId).Items.FirstOrDefault(); var activityData = NidanBusinessService.RetrieveActivity(organisationId, activityTask.ActivityId, e => true); var assignTos = NidanBusinessService.RetrieveActivityAssignPersonnels(organisationId, activityTask.CentreId, activityData.ActivityAssigneeGroupId).Items.Select(e => e.Personnel).ToList(); var monitoredByIds = NidanBusinessService.RetrievePersonnels(organisationId, e => true).Items.ToList(); var startDate = activityData.StartDate; var endDate = activityData.EndDate; var numberOfDays = (endDate - startDate).TotalDays; var startTime = activityData.StartHour + ":" + activityData.StartMinute + " " + activityData.StartTimeSpan; var endTime = activityData.EndHour + ":" + activityData.EndMinute + " " + activityData.EndTimeSpan; var numberOfHours = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime)); var monitoredBy = NidanBusinessService.RetrievePersonnel(organisationId, activityData.CreatedBy); var viewModel = new ActivityTaskViewModel { NumberOfDays = numberOfDays, NumberOfHours = numberOfHours, Centres = new SelectList(centres, "CentreId", "Name"), AssignToList = new SelectList(assignTos, "PersonnelId", "FullName"), MonitoredByList = new SelectList(monitoredByIds, "PersonnelId", "FullName"), ActivityTask = activityTask, Activity = activityData, MonitoredById = monitoredBy.PersonnelId, MonitoredByName = monitoredBy.Fullname, ActivityTaskStatus = activityTaskDataGrid?.ActivityTaskStatus }; viewModel.HoursList = new SelectList(viewModel.HoursType, "Id", "Name"); viewModel.MinutesList = new SelectList(viewModel.MinutesType, "Id", "Name"); viewModel.TaskPriorityList = new SelectList(viewModel.TaskPriority, "Value", "Name"); return(View(viewModel)); }