Exemple #1
0
 /// <summary>
 /// A constructor which copies the information from a database user model.
 /// </summary>
 public UserEdit(TCABS_DataLibrary.Models.UserModel userModel)
 {
     UserId       = userModel.UserId;
     Username     = userModel.Username;
     FirstName    = userModel.FirstName;
     LastName     = userModel.LastName;
     EmailAddress = userModel.Email;
     PhoneNumber  = userModel.PhoneNo;
 }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }
            int userId = (int)id;

            TCABS_DataLibrary.Models.UserModel userModel = UserProcessor.SelectUserForUserId(userId);

            UserEdit user = new UserEdit(userModel);

            return(View(user));
        }
Exemple #3
0
        /// <summary>
        /// A constructor which copies the information from a database user model.
        /// </summary>
        public User(TCABS_DataLibrary.Models.UserModel userModel)
        {
            UserId       = userModel.UserId;
            Username     = userModel.Username;
            FirstName    = userModel.FirstName;
            LastName     = userModel.LastName;
            EmailAddress = userModel.Email;
            PhoneNumber  = userModel.PhoneNo;
            Password     = userModel.Password;

            UserRoles     = new HashSet <UserRole>();
            Enrollments   = new HashSet <Enrollment>( );
            UnitOfferings = new HashSet <UnitOffering>( );
        }
        public ActionResult Edit(int?id)
        {
            // Make sure the user is logged in and that they have permission
            if (!IsUserLoggedIn)
            {
                return(RedirectToLogin());
            }
            if (!UserHasPermission(PermissionName.User))
            {
                return(RedirectToPermissionDenied());
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int userId = ( int )id;

            TCABS_DataLibrary.Models.UserModel userModel = UserProcessor.SelectUserForUserId(userId);

            UserEdit user = new UserEdit(userModel);

            return(View(user));
        }
        /// <summary>
        /// Check if the contained username and password match a user.
        /// The password property will be cleared on exit.
        /// </summary>
        /// <returns>The user data which matches the valid username and password, or null if username and/or password was incorrect.</returns>
        public User ValidateUser()
        {
            User result = null;
            bool isUsernameAndPasswordValid = false;

            TCABS_DataLibrary.Models.UserModel user = null;

            // Try to get the user data from the database
            try
            {
                user = UserProcessor.SelectUserForUsername(Username);
            }
            catch { }

            // Check if any user data was found
            if (user != null)
            {
                // Check if password salt exists
                if (user.PasswordSalt != null)
                {
                    // Check if the login password matches the stored password
                    // Exit here if incorrect
                    if (user.Password == HashPassword(Password, user.PasswordSalt))
                    {
                        isUsernameAndPasswordValid = true;
                    }
                }
                else
                {
                    // No password exists
                    // This should only be the case for debugging, where data might have been directly added to the database
                    // If user data is entered via the normal means then password salt should always exist
                    // Create a new password salt
                    user.PasswordSalt = CreatePasswordSalt();

                    // Check if the login password matches the stored password
                    // Assume password is plain-text because no salt exists yet
                    if (user.Password == Password)
                    {
                        isUsernameAndPasswordValid = true;

                        // If here then password is correct
                        // Make a hashed version of the password
                        user.Password = HashPassword(Password, user.PasswordSalt);

                        // Save the new hashed password and new password salt in the database
                        UserProcessor.UpdatePassword(user.UserId, user.Password, user.PasswordSalt);
                    }
                }

                // If the username and password is value then record the user information
                if (isUsernameAndPasswordValid)
                {
                    result = new User
                    {
                        UserId       = user.UserId,
                        Username     = user.Username,
                        FirstName    = user.FirstName,
                        LastName     = user.LastName,
                        EmailAddress = user.Email,
                        PhoneNumber  = user.PhoneNo,
                    };
                }
            }

            // Clear the password data and then return the result
            Password = null;
            return(result);
        }
        //public UnitOffering( TCABS_DataLibrary.Models.UnitOfferingModel unitOfferingModel )
        //{
        //   UnitOfferingId = unitOfferingModel.UnitOfferingId;
        //   ConvenorId = unitOfferingModel.ConvenorId;
        //   UnitId = unitOfferingModel.UnitId;
        //   TeachingPeriodId = unitOfferingModel.TeachingPeriodId;
        //   YearId = unitOfferingModel.YearId;

        //   Enrollments = new HashSet<Enrollment>( );
        //   ProjectOfferings = new HashSet<Team>( );
        //}

        public UnitOffering(TCABS_DataLibrary.Models.UnitOfferingModel unitOffering,
                            TCABS_DataLibrary.Models.UnitModel unit,
                            TCABS_DataLibrary.Models.TeachingPeriodModel teachingperiod,
                            TCABS_DataLibrary.Models.YearModel year,
                            TCABS_DataLibrary.Models.UserModel convenor,
                            List <TCABS_DataLibrary.Models.ProjectOfferingModel> projectOfferings,
                            List <TCABS_DataLibrary.Models.EnrollmentModel> enrollments)
        {
            UnitOfferingId   = unitOffering.UnitOfferingId;
            UnitId           = unitOffering.UnitId;
            TeachingPeriodId = unitOffering.TeachingPeriodId;
            YearId           = unitOffering.YearId;
            ConvenorId       = unitOffering.ConvenorId;

            Unit = new Unit( );
            if (unit?.UnitId == UnitId)
            {
                Unit.Name   = unit.Name;
                Unit.UnitId = unit.UnitId;
            }

            TeachingPeriod = new TeachingPeriod( );
            if (teachingperiod?.TeachingPeriodId == TeachingPeriodId)
            {
                TeachingPeriod.Name             = teachingperiod.Name;
                TeachingPeriod.Month            = teachingperiod.Month;
                TeachingPeriod.Day              = teachingperiod.Day;
                TeachingPeriod.TeachingPeriodId = teachingperiod.TeachingPeriodId;
            }

            Year = new Year( );
            if (year?.YearId == YearId)
            {
                Year.YearValue = year.Year;
                Year.YearId    = year.YearId;
            }

            Convenor = new User( );
            if (convenor?.UserId == ConvenorId)
            {
                Convenor.Username = convenor.Username;
                Convenor.UserId   = convenor.UserId;
            }

            ProjectOfferings = new List <ProjectOffering>( );

            foreach (var po in projectOfferings)
            {
                var projectOffering = new ProjectOffering( )
                {
                    ProjectOfferingId = po.ProjectOfferingId,
                    UnitOfferingId    = po.UnitOfferingId,
                    ProjectId         = po.ProjectId
                };
                projectOffering.UnitOffering = this;
                //var supervisorModel = UserProcessor.SelectUserForUserId( projectOffering. );
                //projectOffering.Supervisor = new User( )
                //{
                //   UserId = supervisorModel.UserId,
                //   Username = supervisorModel.Username
                //};

                ProjectOfferings.Add(projectOffering);
            }

            Enrollments = new List <Enrollment>( );
            foreach (var e in enrollments)
            {
                var enrollment = new Enrollment( )
                {
                    EnrollmentId   = e.EnrollmentId,
                    UnitOfferingId = e.UnitOfferingId,
                    UserId         = e.UserId,
                    UnitOffering   = this
                };

                var userData = UserProcessor.SelectUserForUserId(e.UserId);
                var user     = new User( )
                {
                    UserId    = userData.UserId,
                    Username  = userData.Username,
                    FirstName = userData.FirstName,
                    LastName  = userData.LastName,
                };
                enrollment.Student = user;

                Enrollments.Add(enrollment);
            }
        }