Beispiel #1
0
        /// <summary>
        /// The main page of the year controller
        /// Shows a list of all units in the system
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Year))
            {
                return(RedirectToPermissionDenied());
            }

            // Set the page message
            ViewBag.Message = "Years List";

            // Get all years from the database
            var yearModels = YearProcessor.SelectYears( );

            // Change the format of the year list
            List <Year> years = new List <Year>( );

            foreach (var y in yearModels)
            {
                years.Add(new Year(y));
            }

            // Return the view, with the list of years
            return(View(years));
        }
Beispiel #2
0
        public ActionResult Delete(Year year)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Year))
            {
                return(RedirectToPermissionDenied());
            }

            try
            {
                // Ensure no UnitOffering is using given Year
                if (UnitOfferingProcessor.SelectUnitOfferingCountForYear(year.YearId) > 0)
                {
                    throw new DataException("Unable to delete Year. One or more Unit Offerings require it.");
                }

                // Attempt to Delete Year
                YearProcessor.DeleteYear(year.YearId);

                // If delete successful return to Index
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                // Show any errors
                ModelState.AddModelError("", e.Message);
            }
            // If unsuccessful reload data and return to View.
            db.GetYear(year.YearId);
            return(View(db));
        }
        /// <summary>
        /// Navigate to Details page for a Unit Offering
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.UnitOffering))
            {
                return(RedirectToPermissionDenied());
            }

            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                var unitOfferingModel = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(id);
                if (unitOfferingModel == null)
                {
                    return(RedirectToIndexIdNotFound(id));
                }

                var unit           = UnitProcessor.SelectUnitForUnitId(unitOfferingModel.UnitId);
                var teachingPeriod = TeachingPeriodProcessor.SelectTeachingPeriodForTeachingPeriodId(unitOfferingModel.TeachingPeriodId);
                var year           = YearProcessor.SelectYearForYearId(unitOfferingModel.YearId);
                var convenor       = UserProcessor.SelectUserForUserId(unitOfferingModel.ConvenorId);

                var projectOfferings = ProjectOfferingProcessor.SelectProjectOfferingsForUnitOfferingId(id);
                var enrollments      = EnrollmentProcessor.LoadEnrollmentsForUnitOffering(id);

                // Convert the model data to non-model data
                // Pass the data to the view
                var unitOffering = new UnitOffering(unitOfferingModel, unit, teachingPeriod, year, convenor, projectOfferings, enrollments);

                ViewBag.UserId = new SelectList(unitOffering.GetStudents( ), "UserId", "Username", null);
                return(View(unitOffering));
            }
            catch (Exception e)
            {
                return(RedirectToIndex(e));
            }

            // Find Unit Offering
            //db.GetUnitOffering( id );

            // Populate Student Drop Down List for to add new Enrollments
            //PopulateStudentDropDownList( );

            // Navigate to View
            //return View( db );
        }
        public Year GetYearForYearValue(int yearValue)
        {
            var data = YearProcessor.SelectYearForYearValue(yearValue);
            var year = new Year( )
            {
                YearId    = data.YearId,
                YearValue = data.Year
            };

            Year = year;
            return(Year);
        }
Beispiel #5
0
        private void GetUnitOffering(int id)
        {
            var data = UnitOfferingProcessor.SelectUnitOfferingForUnitOfferingId(id);

            UnitOffering = new UnitOffering( )
            {
                UnitOfferingId   = data.UnitOfferingId,
                TeachingPeriodId = data.TeachingPeriodId,
                YearId           = data.YearId,
                ConvenorId       = data.ConvenorId,
                UnitId           = data.UnitId,
            };

            var teachingperiodData = TeachingPeriodProcessor.SelectTeachingPeriodForTeachingPeriodId(UnitOffering.TeachingPeriodId);

            UnitOffering.TeachingPeriod = new TeachingPeriod( )
            {
                TeachingPeriodId = teachingperiodData.TeachingPeriodId,
                Name             = teachingperiodData.Name,
                Day   = teachingperiodData.Day,
                Month = teachingperiodData.Month
            };
            var yearData = YearProcessor.SelectYearForYearId(UnitOffering.YearId);

            UnitOffering.Year = new Year( )
            {
                YearId    = yearData.YearId,
                YearValue = yearData.Year
            };

            var convenorData = UserProcessor.SelectUserForUserId(UnitOffering.ConvenorId);

            UnitOffering.Convenor = new User( )
            {
                UserId   = convenorData.UserId,
                Username = convenorData.Username
            };

            var unitData = UnitProcessor.SelectUnitForUnitId(UnitOffering.UnitId);

            UnitOffering.Unit = new Unit( )
            {
                UnitId = unitData.UnitId,
                Name   = unitData.Name
            };
        }
        public List <Year> GetYears( )
        {
            var yearData = YearProcessor.SelectYears( );

            Years = new List <Year>( );
            foreach (var row in yearData)
            {
                var year = new Year( )
                {
                    YearId    = row.YearId,
                    YearValue = row.Year
                };

                Years.Add(year);
            }
            return(Years);
        }
Beispiel #7
0
        public ActionResult Create(Year model)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.Year))
            {
                return(RedirectToPermissionDenied());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    // Attempt to Insert Year
                    YearProcessor.InsertYear(model.YearValue);

                    // If Insert successful return to Index
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                    // Show any datalayer errors
                    var errors = ModelState.Values.SelectMany(v => v.Errors);
                }
            }
            else
            {
                // show any modelstate errors
                var errors = ModelState.Values.SelectMany(v => v.Errors);
            }

            // If unsuccessful return to View
            return(View( ));
        }