Пример #1
0
        private bool ValidClass(CreateClassModel aCreateClassModel)
        {
            if (string.IsNullOrEmpty(aCreateClassModel.UniversityId) || aCreateClassModel.UniversityId.Equals(Constants.SELECT)) {
                theValidationDictionary.AddError("UniversityId", aCreateClassModel.UniversityId, "A university is required.");
            }

            Regex myAlphaNumericRegex = new Regex("^[a-zA-Z0-9]+$");
            if (!myAlphaNumericRegex.IsMatch(aCreateClassModel.ClassSubject)) {
                theValidationDictionary.AddError("ClassSubject", aCreateClassModel.ClassSubject, "A class code must be provided and must be only letters and numbers.");
            }

            if (!myAlphaNumericRegex.IsMatch(aCreateClassModel.ClassCourse)) {
                theValidationDictionary.AddError("ClassCourse", aCreateClassModel.ClassCourse, "A class code must be provided and must be only letters and numbers.");
            }

            if (string.IsNullOrEmpty(aCreateClassModel.ClassTitle)) {
                theValidationDictionary.AddError("ClassTitle", aCreateClassModel.ClassTitle, "A class title must be provided.");
            }

            if (theClassRepository.GetClass(aCreateClassModel.ClassSubject, aCreateClassModel.ClassCourse) != null) {
                theValidationDictionary.AddError("Class", string.Empty, "That class already exists.");
            }

            return theValidationDictionary.isValid;
        }
Пример #2
0
        public ActionResult Create(string universityId)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }
            try {
                User myUser = GetUserInformatonModel().Details;

                if (!UniversityHelper.IsFromUniversity(myUser, universityId)) {
                    return SendToResultPage(UOMConstants.NOT_APART_OF_UNIVERSITY);
                }

                CreateClassModel myClassModel = new CreateClassModel() {

                };

                LoggedInWrapperModel<CreateClassModel> myLoggedIn = new LoggedInWrapperModel<CreateClassModel>(myUser);
                myLoggedIn.Set(myClassModel);

                return View("Create", myLoggedIn);
            } catch (Exception myExpcetion) {
                LogError(myExpcetion, CREATE_CLASS_ERROR);
                return SendToErrorPage(CREATE_CLASS_ERROR);
            }
        }
Пример #3
0
        public Class CreateClass(UserInformationModel<User> aCreatedByUser, CreateClassModel aCreateClassModel)
        {
            if (!ValidClass(aCreateClassModel)) {
                return null;
            }

            Class myClass= theClassRepository.CreateClass(aCreatedByUser.Details, aCreateClassModel.UniversityId,
                                                          aCreateClassModel.ClassSubject.Trim().ToUpper(),
                                                          aCreateClassModel.ClassCourse.Trim().ToUpper(),
                                                          aCreateClassModel.ClassTitle.Trim());

            return myClass;
        }
Пример #4
0
        public ActionResult Create(CreateClassModel aClass)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }
            try {
                Class myResult = theClassService.CreateClass(GetUserInformatonModel(), aClass);
                if (myResult != null) {
                    TempData["Message"] = SuccessMessage("Class added! You can now tag books to it!");
                }
            } catch (Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                TempData["Message"] += ErrorKeys.ERROR_MESSAGE;
                theValidationDictionary.ForceModleStateExport();
            }

            return RedirectToAction("Create");
        }