public ActionResult Index() { DepartmentListViewModel model = new DepartmentListViewModel(); model.Departments = _entities.acq_department_master.ToList(); return(View(model)); }
// GET: Departments public ActionResult Index() { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"SELECT d.Id, d.Name, d.Budget, COUNT(e.DepartmentId) AS Employees FROM Department d LEFT JOIN Employee e ON d.Id = e.DepartmentId GROUP BY d.Id, d.Name, d.Budget"; var reader = cmd.ExecuteReader(); var departments = new List <DepartmentListViewModel>(); while (reader.Read()) { var department = new DepartmentListViewModel() { DepartmentId = reader.GetInt32(reader.GetOrdinal("Id")), Name = reader.GetString(reader.GetOrdinal("Name")), Budget = reader.GetInt32(reader.GetOrdinal("Budget")), EmployeeCount = reader.GetInt32(reader.GetOrdinal("Employees")) }; departments.Add(department); } reader.Close(); return(View(departments)); } } }
public ActionResult AddEmployee(Employee employee) { var departmentList = new DepartmentListViewModel().GetDepartmentsListItems(); ViewBag.departmentList = departmentList; var roleList = new EmployeeListViewModel().GetRoles(); ViewBag.roleList = roleList; if (!ModelState.IsValid) { return(View("AddEmployee")); } if (Request.Files.Count > 0) { string fileName = $"{Guid.NewGuid()}{Path.GetFileName(Request.Files[0].FileName)}"; string extension = Path.GetExtension(Request.Files[0].FileName); string filePath = "~/Images/" + fileName + extension; Request.Files[0].SaveAs(Server.MapPath(filePath)); if (extension == "") { employee.EmployeeImage = "~/Icons/no-image-icon-4.png"; } else { employee.EmployeeImage = filePath; } } _employeeManager.Add(employee); return(RedirectToAction("Index")); }
public async Task <ApiResponse <DepartmentListViewModel> > GetDepartmentById(Guid id) { ApiResponse <DepartmentListViewModel> response = new ApiResponse <DepartmentListViewModel>(); try { var query = await this.GetByIdAsync(id); if (query == null) { return(ResponseMessage.ErrorMessage <DepartmentListViewModel>("Record not found")); } DepartmentListViewModel details = new DepartmentListViewModel { Name = query.Name, Description = query.Description, Id = query.Id.ToString(), }; return(ResponseMessage.SuccessMessage("", details)); } catch (Exception ex) { return(ResponseMessage.ErrorMessage <DepartmentListViewModel>(ex.Message)); } }
public ActionResult Index() { var model = new DepartmentListViewModel(); model.Departments = _departmentService.GetList(); return(View(model)); }
// GET: /Department/ public ActionResult Index() { var departmentListViewModel = new DepartmentListViewModel(); departmentListViewModel.DepartmentList = departmentListViewModel.CopyModelToViewModel(_departmentService.GetAllDepartment()); return(View(departmentListViewModel)); }
public PartialViewResult GetListofDepartment() { var departmentListViewModel = new DepartmentListViewModel(); var departmentList = departmentListViewModel.CopyModelToViewModel(_departmentService.GetAllDepartment()); return(PartialView("_DepartmentList", departmentList)); }
public async Task <ActionResult> Index(int page = 1) { IEnumerable <DepartmentDTO> dDto = await _departmentService.GetAllAsync(); dDto = _departmentService.GetPage(dDto, page); // Paging InitializeMapper(); IEnumerable <DepartmentViewModel> departments = Mapper.Map <IEnumerable <DepartmentDTO>, IEnumerable <DepartmentViewModel> >(dDto); DepartmentListViewModel model = new DepartmentListViewModel { Departments = departments, PageInfo = _departmentService.PageInfo }; if (Request.Headers["X-Requested-With"] == "XMLHttpRequest") { _logger.Info("Executed async request"); var transformModel = new { Departments = model.Departments.Select(d => new { d.Id, d.Code, d.DepartmentName, OrganizationName = d.Organization.Name, Manager = d.Manager != null ? d.Manager.LastName + " " + d.Manager.FirstName + " " + d.Manager.Patronymic : "" }).ToArray(), model.PageInfo }; return(Json(transformModel, JsonRequestBehavior.AllowGet)); } _logger.Info("Executed sync request"); return(View("Index", model)); }
public ActionResult List() { DepartmentListViewModel viewModel = new DepartmentListViewModel(); List <CourseRating> courseRatings = CourseRatingRepositorySQL.Instance.listByCategoryAndSemesters( Convert.ToInt32(GlobalVariables.CurrentCategory), (GlobalVariables.CurrentSemester == "-1" ? StaticData.semesters.Take(3).Select(y => y.semester).ToArray() : new[] { GlobalVariables.CurrentSemester })) .Where(p => p.classSize >= p.responses) .ToList(); var courseRatingsDept = courseRatings.Select(p => { var result = new { departmentID = StaticData.courseDeptMapping[p.courseID.ToString()], classSize = p.classSize, responses = p.responses, ratings = p.ratings }; return(result); }); int totalResponses = 0; int totalStudents = 0; double averageRating = 0.0; List <DepartmentDomain> departments = StaticData.departmentList.Select(p => { var responses = courseRatingsDept.Where(x => x.departmentID == p.departmentID).Select(y => y.responses).Sum(z => z); var students = courseRatingsDept.Where(x => x.departmentID == p.departmentID).Select(y => y.classSize).Sum(z => z); totalResponses += responses; totalStudents += students; averageRating += courseRatingsDept .Where(x => x.departmentID == p.departmentID).Sum(z => z.responses * z.ratings[0].averageRating); return(new DepartmentDomain { name = p.name, collegeID = p.collegeID, departmentID = p.departmentID, collegeName = StaticData.collegeList.Where(u => u.collegeID == p.collegeID).FirstOrDefault().name, rating = courseRatingsDept .Where(x => x.departmentID == p.departmentID).Sum(z => ((double)z.responses / (double)responses) * z.ratings[0].averageRating).ToString("#.##"), responses = responses.ToString(), students = students.ToString(), responseRate = ((double)responses / (double)students).ToString("p1") }); }).Where(t => Convert.ToInt32(t.students) > 0).ToList(); viewModel.departments = departments; viewModel.totalResponses = totalResponses.ToString("N0"); viewModel.totalStudents = totalStudents.ToString("N0"); viewModel.averageResponseRate = ((double)totalResponses / (double)totalStudents).ToString("p1"); viewModel.averageRating = (averageRating / (double)totalResponses).ToString("#.##"); viewModel.currentSemester = (GlobalVariables.CurrentSemester == "-1" ? "the past three semesters" : GlobalVariables.CurrentSemester.Split(' ')[1] + " " + GlobalVariables.CurrentSemester.Split(' ')[0]); return(View(viewModel)); }
public ActionResult DepartmentList(int formid) { DepartmentListViewModel model = new DepartmentListViewModel { FormId = formid }; return(View(model)); }
public ActionResult Index() { var model = new DepartmentListViewModel { Departments = _departmentManager.GetAll() }; return(View(model)); }
public IActionResult Index() { var model = new DepartmentListViewModel { Departments = _departmentService.GetAll() }; return(View(model)); }
public ViewViewComponentResult Invoke() { var model = new DepartmentListViewModel { Departments = _departmentService.GetAll(), CurrentDepartment = Convert.ToInt32(HttpContext.Request.Query["departmentId"]) }; return(View(model)); }
public ActionResult AddEmployee() { var departmentList = new DepartmentListViewModel().GetDepartmentsListItems(); ViewBag.departmentList = departmentList; var roleList = new EmployeeListViewModel().GetRoles(); ViewBag.roleList = roleList; return(View()); }
public void Test_GetContextedDeptVM_with_ValidDept() { // Arrange StubHttpConnection stub_connection = new StubHttpConnection(); List <CourseModel> test_courseList = new List <CourseModel>(); CourseModel dummy_courseToAttach1 = new CourseModel(); dummy_courseToAttach1.Id = "1000"; dummy_courseToAttach1.Department = "STAT"; dummy_courseToAttach1.Name = "Should be in final list"; dummy_courseToAttach1.Difficulty = 5.55; dummy_courseToAttach1.DifficultyCount = 9; dummy_courseToAttach1.SectionRatings = new Dictionary <string, Dictionary <string, double> > { { "test_person1", new Dictionary <string, double> { { "rating", 6.9 }, { "count", 10 } } } }; CourseModel dummy_courseToAttach2 = new CourseModel(); dummy_courseToAttach2.Id = "2000"; dummy_courseToAttach2.Department = "STAT"; dummy_courseToAttach2.Name = "Should be final list"; dummy_courseToAttach2.Difficulty = 7.9; dummy_courseToAttach2.DifficultyCount = 7; dummy_courseToAttach2.SectionRatings = new Dictionary <string, Dictionary <string, double> > { { "test_person2", new Dictionary <string, double> { { "rating", 3.4 }, { "count", 15 } } } }; test_courseList.Add(dummy_courseToAttach1); test_courseList.Add(dummy_courseToAttach2); stub_connection.SetDummyResponse(JsonConvert.SerializeObject(test_courseList)); DepartmentListViewModel deptListVmToTest = new DepartmentListViewModel(stub_connection); // Act DepartmentViewModel deptVmToTest = deptListVmToTest.GetContextedDeptVM(new DepartmentModel() { Name = "STAT" });; // Assert Assert.IsTrue(deptVmToTest.DepartmentName.Equals("STAT"), "returned department not the same as requested"); Assert.IsFalse(deptVmToTest == null, "department was null even with valid data"); Assert.IsFalse(deptVmToTest.CourseList == null, "course list was null for valid data"); Assert.IsFalse(deptVmToTest.CourseList.Count == 0, "courses not generated for valid department"); }
public ActionResult Index() { var departments = _departmentService.GetList(); DepartmentListViewModel model = new DepartmentListViewModel { Department = departments }; return(View(model)); }
public ActionResult UpdateEmployee(int id) { var departmentList = new DepartmentListViewModel().GetDepartmentsListItems(); ViewBag.departmentList = departmentList; var roleList = new EmployeeListViewModel().GetRoles(); ViewBag.roleList = roleList; var employee = _employeeManager.GetById(id); return(View("UpdateEmployee", employee)); }
public MenuModule() { ListDepartmentsCommand = new CategoryCommand<string>(Resources.Departments, Resources.Settings, OnListDepartments); ListMenuItemsCommand = new CategoryCommand<string>(Resources.ProductList, Resources.Products, OnListMenuItems); ListScreenMenusCommand = new CategoryCommand<string>(Resources.MenuList, Resources.Products, OnListScreenMenus); ListMenuItemPropertyGroupsCommand = new CategoryCommand<string>(Resources.ModifierGroups, Resources.Products, OnListMenuItemPropertyGroupsCommand); ListPricesCommand = new CategoryCommand<string>(Resources.BatchPriceList, Resources.Products, OnListPrices); ListTicketTagGroupsCommand = new CategoryCommand<string>(Resources.TicketTags, Resources.Settings, OnListTicketTags) { Order = 10 }; ListMenuItemPriceDefinitionsCommand = new CategoryCommand<string>(Resources.PriceDefinitions, Resources.Products, OnListMenuItemPriceDefinitions); ListVatTemplatesCommand = new CategoryCommand<string>(Resources.VatTemplates, Resources.Products, OnListVatTemplates); ListTaxServiceTemplates = new CategoryCommand<string>(Resources.TaxServiceTemplates, Resources.Products, OnListTaxServiceTemplates); PermissionRegistry.RegisterPermission(PermissionNames.ChangeDepartment, PermissionCategories.Department, Resources.CanChangeDepartment); foreach (var department in AppServices.MainDataContext.Departments) { PermissionRegistry.RegisterPermission(PermissionNames.UseDepartment + department.Id, PermissionCategories.Department, department.Name); } EventServiceFactory.EventService.GetEvent<GenericEvent<VisibleViewModelBase>>().Subscribe(s => { if (s.Topic == EventTopicNames.ViewClosed) { if (s.Value == _menuItemListViewModel) _menuItemListViewModel = null; if (s.Value == _screenMenuListViewModel) _screenMenuListViewModel = null; if (s.Value == _departmentListViewModel) _departmentListViewModel = null; if (s.Value == _menuItemPropertyGroupListViewModel) _menuItemPropertyGroupListViewModel = null; if (s.Value == _priceListViewModel) _priceListViewModel = null; if (s.Value == _ticketTagGroupListViewModel) _ticketTagGroupListViewModel = null; if (s.Value == _menuItemPriceDefinitionListViewModel) _menuItemPriceDefinitionListViewModel = null; if (s.Value == _vatTemplateListViewModel) _vatTemplateListViewModel = null; if (s.Value == _taxServiceTemplateListViewModel) _taxServiceTemplateListViewModel = null; } }); }
public void Test_GenerateDepartmentList_with_NullServerResponse() { // Arrange StubHttpConnection stub_connection = new StubHttpConnection(); stub_connection.SetDummyResponse(null); DepartmentListViewModel vmToTest = new DepartmentListViewModel(stub_connection); // Act vmToTest.GenerateDepartmentList(); // Assert Assert.IsTrue(vmToTest.DepartmentList.Count == 0, "Department was added with null server response"); }
public void Test_GetContextedDeptVM_with_NullArgs() { // Arrange StubHttpConnection stub_connection = new StubHttpConnection(); DepartmentListViewModel deptListVmToTest = new DepartmentListViewModel(stub_connection); // Act DepartmentViewModel deptVmToTest = deptListVmToTest.GetContextedDeptVM(null); // Assert Assert.IsTrue(deptVmToTest == null, "contexted department was not null even with null data"); }
// GET: Department public ActionResult Index() { try { var Departments = _department.GetAll(); var dlvm = new DepartmentListViewModel { departments = Departments }; return(View(dlvm)); } catch (Exception ex) { //Log exception return(View(ex.Message, "Error")); } }
public async Task Index_SyncRequest_RetrievesPageInfoPropertyFromModel() { Mock <DepartmentService> mock = new Mock <DepartmentService>(); mock.Setup(m => m.PageInfo).Returns(new PageInfo() { TotalItems = 9, PageSize = 3, PageNumber = 3 }); DepartmentController controller = GetNewDepartmentControllerWithControllerContext(null, mock.Object, null); ViewResult result = (await controller.Index()) as ViewResult; DepartmentListViewModel model = result.ViewData.Model as DepartmentListViewModel; Assert.AreEqual(9, model.PageInfo.TotalItems); Assert.AreEqual(3, model.PageInfo.PageSize); Assert.AreEqual(3, model.PageInfo.PageNumber); Assert.AreEqual(3, model.PageInfo.TotalPages); }
public void Test_GenerateDepartmentList_with_ValidServerResponse() { // Arrange StubHttpConnection stub_connection = new StubHttpConnection(); stub_connection.SetDummyResponse("[\"TestDept1\",\"TestDept2\",\"TestDept3\"]"); DepartmentListViewModel vmToTest = new DepartmentListViewModel(stub_connection); // Act vmToTest.GenerateDepartmentList(); // Assert Assert.IsTrue(vmToTest.DepartmentList.Any(d => d.Name.Equals("TestDept1")), "Expected department not found"); Assert.IsTrue(vmToTest.DepartmentList.Any(d => d.Name.Equals("TestDept2")), "Expected department not found"); Assert.IsTrue(vmToTest.DepartmentList.Any(d => d.Name.Equals("TestDept3")), "Expected department not found"); Assert.IsTrue(vmToTest.DepartmentList.Count == 3, "Not all departments were added"); }
public ActionResult List() { var departmentsInDb = _departmentService.GetDepartments(); var departmentDtos = new List <DepartmentDto>(); foreach (var department in departmentsInDb) { var departmentDto = Mapper.Map <Department, DepartmentDto>(department); departmentDto.FacultyDto = Mapper.Map <Faculty, FacultyDto>(department.Faculty); departmentDtos.Add(departmentDto); } var viewModel = new DepartmentListViewModel { DepartmentDtos = departmentDtos, }; return(View(viewModel)); }
public static DepartmentListViewModel ToViewModel(this IEnumerable <DepartmentAggregate> deps) { DepartmentListViewModel viewModel = null; if (deps != null) { viewModel = new DepartmentListViewModel() { Total = deps.Count(), Departments = deps.Select(x => new DepartmentemViewModel() { Id = x.Id.ToString(), Name = x.Name, Description = x.Description, FacilityName = x.FacilityName, }), }; } return(viewModel); }
public async Task Index_SyncRequest_RetrievesDepartmentsPropertyFromModel() { Mock <DepartmentService> mock = new Mock <DepartmentService>(); mock.Setup(m => m.GetPage(It.IsAny <IEnumerable <DepartmentDTO> >(), It.IsAny <int>())).Returns(new DepartmentDTO[] { new DepartmentDTO { Id = 1, Code = 101, DepartmentName = "IT" } }); DepartmentController controller = GetNewDepartmentControllerWithControllerContext(null, mock.Object, null); ViewResult result = (await controller.Index()) as ViewResult; DepartmentListViewModel model = result.ViewData.Model as DepartmentListViewModel; Assert.AreEqual(1, model.Departments.Count()); Assert.AreEqual(1, model.Departments.FirstOrDefault().Id); Assert.AreEqual(101, model.Departments.FirstOrDefault().Code); Assert.AreEqual("IT", model.Departments.FirstOrDefault().DepartmentName); }
private void OnListDepartments(string obj) { if (_departmentListViewModel == null) _departmentListViewModel = new DepartmentListViewModel(); CommonEventPublisher.PublishViewAddedEvent(_departmentListViewModel); }