コード例 #1
0
        /// <summary>
        /// Lists all the departments in the database
        /// </summary>
        /// <returns>
        ///     If successfull in retreiving the data from the database, then returns the data to the view
        ///     If not -> Calls the Error Action to invoke the error message.
        /// </returns>
        /// <example>
        /// GET: Department/ListDepartments
        /// </example>
        public ActionResult ListDepartments(int PageNum = 0)
        {
            ShowDepartment ViewModel = new ShowDepartment();

            ViewModel.isadmin = User.IsInRole("admin");

            string url = "DepartmentData/ListDepartments";
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                IEnumerable <DepartmentsDto> ListOfDepartments = response.Content.ReadAsAsync <IEnumerable <DepartmentsDto> >().Result;

                // -- Start of Pagination Algorithm --

                // Find the total number of players
                int DepartmentCount = ListOfDepartments.Count();
                // Number of players to display per page
                int PerPage = 4;
                // Determines the maximum number of pages (rounded up), assuming a page 0 start.
                int MaxPage = (int)Math.Ceiling((decimal)DepartmentCount / PerPage) - 1;

                // Lower boundary for Max Page
                if (MaxPage < 0)
                {
                    MaxPage = 0;
                }
                // Lower boundary for Page Number
                if (PageNum < 0)
                {
                    PageNum = 0;
                }
                // Upper Bound for Page Number
                if (PageNum > MaxPage)
                {
                    PageNum = MaxPage;
                }

                // The Record Index of our Page Start
                int StartIndex = PerPage * PageNum;

                //Helps us generate the HTML which shows "Page 1 of ..." on the list view
                ViewData["PageNum"]     = PageNum;
                ViewData["PageSummary"] = " " + (PageNum + 1) + " of " + (MaxPage + 1) + " ";

                // -- End of Pagination Algorithm --

                url      = "DepartmentData/getdepartmentspage/" + StartIndex + "/" + PerPage;
                response = client.GetAsync(url).Result;

                IEnumerable <DepartmentsDto> SelectedDepartmentsPage = response.Content.ReadAsAsync <IEnumerable <DepartmentsDto> >().Result;

                ViewModel.departments = SelectedDepartmentsPage;
                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
コード例 #2
0
        public ActionResult Details(int id)
        {
            ShowDepartment showdepartment = new ShowDepartment();

            string url = "departmentdata/finddepartment/" + id;

            HttpResponseMessage response = client.GetAsync(url).Result;

            // If the response is a success, proceed
            if (response.IsSuccessStatusCode)
            {
                // Fetch the response content into IEnumerable<DepartmentDto>

                DepartmentDto department = response.Content.ReadAsAsync <DepartmentDto>().Result;
                showdepartment.Department = department;

                url      = "DepartmentData/FindJobPostingsForDepartment/" + id;
                response = client.GetAsync(url).Result;
                IEnumerable <JobPostingDto> jobPostings = response.Content.ReadAsAsync <IEnumerable <JobPostingDto> >().Result;
                showdepartment.JobPostings = jobPostings;
                return(View(showdepartment));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        // GET: Department/Details/5
        public ActionResult Details(int id)
        {
            ShowDepartment      ViewModel = new ShowDepartment();
            string              url       = "departmentdata/finddepartment/" + id;
            HttpResponseMessage response  = client.GetAsync(url).Result;

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into department data transfer object
                DepartmentDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentDto>().Result;
                ViewModel.department = SelectedDepartment;


                // url = "departmentdata/findteamforplayer/" + id;
                // response = client.GetAsync(url).Result;
                // TeamDto SelectedTeam = response.Content.ReadAsAsync<TeamDto>().Result;
                // ViewModel.team = SelectedTeam;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
コード例 #4
0
        //show department
        //show related feedback types
        public ActionResult Show(int id)
        {
            Departments departments = db.Departments.SqlQuery("Select * from Departments where id = @id", new SqlParameter("@id", id)).FirstOrDefault();

            List <FeedbackTypes> types = db.FeedbackTypes.SqlQuery("Select * from FeedbackTypes join FeedbackTypesDepartments on typeId = FeedbackTypes_typeId where Departments_id = @id", new SqlParameter("@id", id)).ToList();

            ShowDepartment show = new ShowDepartment();

            show.Department = departments;
            show.types      = types;
            return(View(show));
        }
コード例 #5
0
 // GET: Manage/Department/Create
 public ActionResult Create(Guid? id)
 {
     var departmentServices = ServiceLocator.Instance.GetService<IDepartmentServices>();
     var updateDepartment = new ShowDepartment();
     var accounts = new List<ShowAccount>();
     var ownerId = Guid.Empty;
     if (id.HasValue)
     {
         updateDepartment = departmentServices.Get(id.Value);
         var accountServices = ServiceLocator.Instance.GetService<IAccountServices>();
         accounts = accountServices.GetAccountsByDepartment(id.Value);
         updateDepartment.OwnerId = departmentServices.GetOwner(id.Value);
     }
     ViewBag.ShowAccounts = new HtmlString(accounts.ToJson());
     ViewBag.updateDepartment = new HtmlString(updateDepartment.ToJson());
     return PartialView();
 }
        public ActionResult Show(int id)
        {
            ShowDepartment ViewModel = new ShowDepartment();
            string         url       = "DepartmentData/FindDepartment/" + id;

            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                DepartmentDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentDto>().Result;
                ViewModel.department = SelectedDepartment;

                url      = "PracticeData/GetPracticesByDepartmentId/" + SelectedDepartment.DepartmentID;
                response = client.GetAsync(url).Result;
                IEnumerable <Practice> listOfPractices = response.Content.ReadAsAsync <IEnumerable <Practice> >().Result;
                ViewModel.listOfPractices = listOfPractices;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }