public async Task <IViewComponentResult> InvokeAsync(int id) { //Get DBModel JoinedEntitysModel errandModel = ((List <JoinedEntitysModel>)await this._httpContext.RequestServices.GetRequiredService <IErrand>().getErrandsList(errId: id)).First(); List <Picture> pics = await this._httpContext.RequestServices.GetRequiredService <IPicture>().GetPictures(errandId: id); errandModel.Pictures = pics; List <Sample> samples = await this._httpContext.RequestServices.GetRequiredService <ISample>().GetSamples(errandId: id); errandModel.Samples = samples; //Fill ViewModel ErrandDetailVM viewModel = new ErrandDetailVM() { //AutoMapper could have been used here //https://github.com/AutoMapper/AutoMapper errandId = errandModel.ErrandId, Place = errandModel.Place, InformerName = errandModel.InformerName, InformerPhone = errandModel.InformerPhone, Observation = errandModel.Observation, InvestigatorInfo = errandModel.InvestigatorInfo, InvestigatorAction = errandModel.InvestigatorAction, Pictures = errandModel.Pictures, Samples = errandModel.Samples, TypeOfCrime = errandModel.TypeOfCrime, RefNumber = errandModel.RefNumber, DateOfObservation = errandModel.DateOfObservation, StatusName = errandModel.StatusName, DepartmentName = errandModel.DepartmentName, EmployeeName = errandModel.EmployeeName }; return(View(viewModel)); }
public async Task <IActionResult> UpdateErrandDetails(ErrandDetailVM errandDetailVM) { string user = this._httpContext.User.Identity.Name; var employeeEntity = await this._httpContext.RequestServices.GetRequiredService <IEmployee>().getEmployee(user); EmployeeModel employeeModel = employeeEntity; //if (user == null) // return View("Login"); //Create and fill Errand for saving Errand errand = new Errand { ErrandID = errandDetailVM.errandId, DepartmentId = errandDetailVM.departmentId, StatusId = errandDetailVM.statusId, EmployeeId = errandDetailVM.employeeId, }; if (employeeModel.RoleTitle == Employee.EMP_ROLE_COORDINATOR) { if (errandDetailVM.statusId == ErrandStatus.ST_REPORTED) { errand.StatusId = ErrandStatus.ST_STARTED; } } if (employeeModel.RoleTitle == Employee.EMP_ROLE_MANAGER) { errand.StatusId = errandDetailVM.noAction == true ? ErrandStatus.ST_NO_ACTION : ErrandStatus.ST_STARTED; errand.InvestigatorInfo = errandDetailVM.information + "\n\n" + errandDetailVM.noActionReason; } if (employeeModel.RoleTitle == Employee.EMP_ROLE_INVESTIGATOR) { errand.InvestigatorAction = errandDetailVM.events; errand.InvestigatorInfo = errandDetailVM.information; errand.StatusId = errandDetailVM.statusId; } //Save Errand await this._httpContext.RequestServices.GetRequiredService <IErrand>().SaveErrand(errand); //Save images if (errandDetailVM.loadImage != null) { await ErrandHelper.saveStream(environment : this._environment, httpContext : this._httpContext, stream_list : errandDetailVM.loadImage, stream_type : "picture", errand_id : errandDetailVM.errandId); } if (errandDetailVM.loadSample != null) { await ErrandHelper.saveStream(environment : this._environment, httpContext : this._httpContext, stream_list : errandDetailVM.loadSample, stream_type : "sample", errand_id : errandDetailVM.errandId); } //Redirect back again return(RedirectToAction("ErrandDetails", new { id = errandDetailVM.errandId })); }
public async Task <ViewResult> ErrandDetails(int id) { string user = this._httpContext.User.Identity.Name; var employeeEntity = await this._httpContext.RequestServices.GetRequiredService <IEmployee>().getEmployee(user); EmployeeModel employeeModel = employeeEntity; //if (user == null) // return View("Login"); //ViewBag.role = user.RoleTitle; //ViewBag.rolename = u.getRoleDisplayName(); //ViewBag.userfullname = u.EmployeeName; JoinedEntitysModel errandModel = (await this._httpContext.RequestServices.GetRequiredService <IErrand>().getErrandsList(errId: id)).First(); ErrandDetailVM errandViewModel = new ErrandDetailVM { errandId = id, }; if (employeeModel.RoleTitle == Employee.EMP_ROLE_COORDINATOR) { errandViewModel.setDepartments(await this._httpContext.RequestServices.GetRequiredService <IDepartment>().getDepartments(), selectedId: errandModel.DepartmentId); } if (employeeModel.RoleTitle == Employee.EMP_ROLE_MANAGER) { errandViewModel.setEmployees(await this._httpContext.RequestServices.GetRequiredService <IEmployee>().getEmployees(employeeModel.DepartmentId), selectedId: errandModel.EmployeeId); errandViewModel.removeEmployee(user); errandViewModel.noAction = errandModel.StatusId == ErrandStatus.ST_NO_ACTION ? true : false; errandViewModel.information = errandModel.InvestigatorInfo; } if (employeeModel.RoleTitle == Employee.EMP_ROLE_INVESTIGATOR) { errandViewModel.events = errandModel.InvestigatorAction; errandViewModel.information = errandModel.InvestigatorInfo; errandViewModel.setStatuses(await this._httpContext.RequestServices.GetRequiredService <IErrandStatus>().getStatuses(), selectedId: errandModel.StatusId); errandViewModel.removeStatus(ErrandStatus.ST_NO_ACTION); } return(View($"ErrandDetails{employeeModel.RoleTitle}", errandViewModel)); }