public IActionResult Edit(long id, DepartmentDetailViewModel model)
        {
            // Check if model is valid
            if (ModelState.IsValid)
            {
                // Validation on Ids
                if (id != model.Id)
                {
                    return(BadRequest("Ids do not match"));
                }

                // Convert vm back to model
                Department department = converter.ViewModelToModel(model);

                // Update department, if success redirect to details
                if (departmentRepository.Update(department))
                {
                    return(RedirectToAction("Details", new { department.Id }));
                }
                else
                {
                    return(View(model));
                }
            }
            return(View());
        }
        /**
         * Purpose: Define Detail method that interract with the Department table to show detail of Department
         *       with the employees assign to that department.
         * Author: Priynaka Garg
         * Method: DepartmentDetail([FromRoute]int id) - When a user on Department page clicks on any Detail hyperlinked Department then page load the detail of that Department",
         */

        public async Task <IActionResult> Details(int id)
        {
            string sql = $@"SELECT d.Id, 
                             d.Name,  
                             e.Id,
                           e.FirstName, 
                           e.LastName,
                           e.DepartmentId
                         FROM Department d 
                LEFT JOIN Employee e on d.Id = e.DepartmentId
                    WHERE d.Id = {id}";

            using (IDbConnection conn = Connection)
            {
                DepartmentDetailViewModel dept      = new DepartmentDetailViewModel();
                IEnumerable <Department>  deptquery = await conn.QueryAsync <Department, Employee, Department>(sql,
                                                                                                               (department, employee) =>
                {
                    dept.Id   = department.Id;
                    dept.Name = department.Name;


                    dept.Employees.Add(employee);
                    return(department);
                }
                                                                                                               );

                return(View(dept));
            }
        }
Esempio n. 3
0
        //[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
        public async Task <IActionResult> Details(DepartmentDetailViewModel formData)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _departmentServices.UpdateDepartment(new Department
                    {
                        DateTimeModified = DateTimeOffset.Now,
                        Title            = formData.Title,
                        Id          = formData.Id,
                        UserAccount = User.Identity.Name
                    });

                    TempData["Message"] = "Changes saved successfully";
                    _logger.LogInformation($"Success: successfully updated {formData.Title} department record by user={@User.Identity.Name.Substring(4)}");
                    return(RedirectToAction("details", new { id = formData.Id }));
                }
            }
            catch (ApplicationException error)
            {
                ModelState.AddModelError("Bank", $"Failed to update record. {formData.Title} Contact IT ServiceDesk for support.");
                _logger.LogError(
                    error,
                    $"FAIL: failed to update {formData.Title} Department. Internal Application Error.; user={@User.Identity.Name.Substring(4)}");
            }

            return(View(formData));
        }
        void DepartmentGrid_OnBtnDeleteClicked(object sender, EventArgs e)
        {
            int id    = int.Parse(this.GetIdFromBtnSender(sender));
            var model = new DepartmentDetailViewModel();

            this.GetById(id, ref model);
            this.FormCreaterDelete.CreateForm(model);
        }
        public IActionResult Create()
        {
            // Setup VM
            DepartmentDetailViewModel vm = new DepartmentDetailViewModel
            {
                Institutions = GetInstitutionsForDropdown().ToList()
            };

            return(View(vm));
        }
Esempio n. 6
0
        public DepartmentDetailPage()
        {
            InitializeComponent();

            var dept = new Department
            {
                Name      = "Unknown",
                Personnel = new List <Personnel>()
            };

            BindingContext = viewModel = new DepartmentDetailViewModel(dept);
        }
        public IActionResult Index(int Id)
        {
            DepartmentDetailViewModel model = new DepartmentDetailViewModel
            {
                Department  = _context.Departments.Include(d => d.Doctors).FirstOrDefault(d => d.Id == Id),
                Departments = _context.Departments.ToList()
            };



            return(View(model));
        }
        public IActionResult Create(DepartmentDetailViewModel model)
        {
            // Check if is valid
            if (ModelState.IsValid)
            {
                // Push to database
                Department department = converter.ViewModelToModel(model);
                long       id         = departmentRepository.Insert(department);

                // Return detail view
                return(RedirectToAction("Details", new { id }));
            }
            return(View());
        }
Esempio n. 9
0
        //[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
        public async Task <IActionResult> Details(Guid id)
        {
            var departmentQuery = await _departmentServices.GetdepartmentById(id);

            if (departmentQuery == null)
            {
                return(NotFound());
            }

            var model = new DepartmentDetailViewModel
            {
                Title = departmentQuery.Title,
                Id    = departmentQuery.Id,
            };

            return(View(model));
        }
        // David Taylor
        // Gets details of department
        // Displays employees of a department on details page
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Department departments = await GetById(id.Value);

            if (departments == null)
            {
                return(NotFound());
            }
            using (IDbConnection conn = Connection)
            {
                string sql = $@"
                SELECT 
                e.Id,
                e.FirstName,
                e.LastName,
                d.Id,
                d.Name
                FROM Department d
                JOIN Employee e ON d.Id = e.DepartmentId
                WHERE d.Id = {id}
                ";
                IEnumerable <Employee> employees = await conn.QueryAsync <Employee, Department, Employee>(
                    sql,
                    (employee, department) => {
                    employee.DepartmentId = department.Id;
                    return(employee);
                });

                DepartmentDetailViewModel viewModel = new DepartmentDetailViewModel();
                viewModel.Departments = departments;
                viewModel.Employees   = employees;
                return(View(viewModel));
            }
        }
Esempio n. 11
0
        public IActionResult Edit(long id)
        {
            // Check if id is set
            if (id < 1)
            {
                return(BadRequest("Id cannot be 0"));
            }

            // Retrieve department
            Department department = departmentRepository.GetById(id);

            if (department == null)
            {
                return(BadRequest("Department could not be found"));
            }

            // Convert and return
            DepartmentDetailViewModel vm = converter.ModelToViewModel(department);

            vm.Institutions = GetInstitutionsForDropdown(vm.Id).ToList();
            return(View(vm));
        }
Esempio n. 12
0
        // GET: Departments/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var department = await _context.Department
                             .SingleOrDefaultAsync(m => m.Id == id);

            if (department == null)
            {
                return(NotFound());
            }

            List <Employee> employees = await _context.Employee.Where(e => e.DepartmentId == id).ToListAsync();


            DepartmentDetailViewModel viewModel = new DepartmentDetailViewModel();

            viewModel.Department = department;
            viewModel.Employees  = employees;
            return(View(viewModel));
        }
Esempio n. 13
0
        public DepartmentDetailPage(DepartmentDetailViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;
        }
        public ViewResult Detail()
        {
            DepartmentDetailViewModel viewModel = new DepartmentDetailViewModel();

            if (Request.QueryString["department"] != null && StaticData.departmentList.Where(p => GlobalFunctions.escapeQuerystringElement(p.name) == GlobalFunctions.escapeQuerystringElement(Request.QueryString["department"].ToString())).Count() == 1)
            {
                Department department = StaticData.departmentList
                                        .Where(p => GlobalFunctions.escapeQuerystringElement(p.name) == GlobalFunctions.escapeQuerystringElement(Request.QueryString["department"].ToString()))
                                        .FirstOrDefault();

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

                //Filter only sections within the department (Not all ratings of a professor who had a course within that department)
                courseRatings = courseRatings.Where(p => StaticData.courseDeptMapping[p.courseID.ToString()] == department.departmentID).ToList();

                List <Instructor> instructorsAll = InstructorRepositorySQL.Instance.listByDepartment(department.departmentID)
                                                   .Where(p => courseRatings.Select(u => u.instructorID).Distinct().Contains(p.instructorID))
                                                   .ToList();

                var instructorDeptMapping = instructorsAll.Select(p => {
                    CourseRating firstRating = courseRatings.Where(u => u.instructorID == p.instructorID).FirstOrDefault();
                    var dept = StaticData.courseList.Where(t => t.courseID == firstRating.courseID).FirstOrDefault().departmentID;
                    return(new
                    {
                        instructorID = p.instructorID,
                        departmentID = dept
                    });
                }).ToList();

                int    totalResponses = 0;
                int    totalStudents  = 0;
                double averageRating  = 0.0;

                List <InstructorDomain> instructors = instructorsAll.Select(p => {
                    var courseRatingInstructor = courseRatings.Where(x => x.instructorID == p.instructorID);
                    var responses = courseRatingInstructor.Select(y => y.responses).Sum(z => z);
                    var students  = courseRatingInstructor.Select(y => y.classSize).Sum(z => z);
                    var semesters = courseRatingInstructor.Select(v => v.semester).Distinct()
                                    .OrderByDescending(t => t, new SemesterComparer());

                    totalResponses += responses;
                    totalStudents  += students;
                    averageRating  += courseRatingInstructor.Sum(z => (double)z.responses * z.ratings[0].averageRating);

                    return(new InstructorDomain
                    {
                        instructorID = p.instructorID,
                        firstName = p.firstName,
                        lastName = p.lastName,
                        responses = responses.ToString(),
                        students = students.ToString(),
                        responseRate = ((double)responses / (double)students).ToString("p1"),
                        department = StaticData.departmentList.Where(x => x.departmentID == instructorDeptMapping.Where(a => a.instructorID == p.instructorID).FirstOrDefault().departmentID).FirstOrDefault().name,
                        lastSemester = (semesters.Count() > 0 ? semesters.FirstOrDefault() : ""),
                        rating = courseRatingInstructor.Sum(z => ((double)z.responses / (double)responses) * z.ratings[0].averageRating).ToString("#.##")
                    });
                }).ToList();

                viewModel.department          = department;
                viewModel.instructors         = instructors;
                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]);
            }
            else
            {
                throw new HttpException(404, "Department not found!");
            }

            return(View(viewModel));
        }