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 <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)); }