Пример #1
0
        public static ParticipantProfileModel convertToModel(Participant participant, bool status, bool validInput)
        {
            ParticipantProfileModel ppm = new ParticipantProfileModel();

            ppm.Id                   = participant.IdParticipant;
            ppm.Email                = participant.Email;
            ppm.ValidInput           = validInput;
            ppm.SuccesChangePassword = status;

            return(ppm);
        }
        public IActionResult Participant()
        {
            //Getting user ID
            int partID = IdentityHelper.getUserID(User);

            //Getting default participant model obj.
            ParticipantProfileModel ppm = ProfileParticipantHelper.getdefaultParticipant(partID);

            ppm.ValidInput = true;

            return(View(ppm));
        }
Пример #3
0
        public static ParticipantProfileModel getdefaultParticipant(int id)
        {
            ParticipantHomepageHelper helper = new ParticipantHomepageHelper();
            ParticipantProfileModel   ppm    = new ParticipantProfileModel();
            var participant = helper.getParticipant(id);

            ppm.Email      = participant.Email;
            ppm.Id         = id;
            ppm.English    = participant.English;
            ppm.ValidInput = false;

            return(ppm);
        }
        public IActionResult SavePasswordParticipant(ParticipantProfileModel ppm)
        {
            //Getting user ID
            int partID = IdentityHelper.getUserID(User);

            ppm.SuccesChangePassword = false;
            var err = "";

            if (ModelState.IsValid && ppm.Password != null)
            {
                //Creating a local version with changes parametes of Participant obj.
                IManageProfileHandler mph     = new ManageProfileHandler(new bachelordbContext());
                Participant           curpart = new Participant
                {
                    Email         = ppm.Email,
                    IdParticipant = partID,
                    Password      = ppm.Password,
                };

                var status = mph.ChangePasswordParticipantDB(curpart, ppm.OldPassword);
                //Check that old password is correct
                if (status.success)
                {
                    ParticipantHomepageHelper helper = new ParticipantHomepageHelper();
                    var curParticipants = helper.getParticipant(partID);
                    //Creates a new part obj. since SuccesChange has to be true to show dialog
                    ParticipantProfileModel sppm =
                        ProfileParticipantHelper.convertToModel(curParticipants, status.success, true);

                    return(View("Participant", sppm));
                }
                else
                {
                    //Error message if Password did not match
                    err = status.errormessage;

                    this.ModelState.AddModelError("OldPassword", err.ToString());
                }
            }
            else
            {
                //Error message if Password was not put in.
                err = "Must Assign a Password";
                this.ModelState.AddModelError("Password", err.ToString());
            }

            return(View("Participant", ProfileParticipantHelper.getdefaultParticipant(partID)));
        }
        public IActionResult SaveEmailParticipant(ParticipantProfileModel pmodel)
        {
            //Getting user ID
            int partID = IdentityHelper.getUserID(User);

            //Checking if there is a valid Email
            if (pmodel.Email == null)
            {
                var err = "A Participant must have a Email";

                this.ModelState.AddModelError("Email", err.ToString());
            }
            else
            {
                if (ModelState.IsValid)
                {
                    //Creating local Participant obj.
                    Participant part = new Participant
                    {
                        Email         = pmodel.Email,
                        IdParticipant = partID,
                        English       = pmodel.English,
                    };

                    // Call Db here
                    IManageProfileHandler mph = new ManageProfileHandler(new bachelordbContext());
                    mph.ChangeProfileParticipantDB(part);

                    return(RedirectToAction("Participant"));
                }
            }


            //Return view to show error message if something wrong happend.
            ParticipantProfileModel ppm = ProfileParticipantHelper.getdefaultParticipant(partID);

            ppm.ValidInput = true;

            return(View("Participant", ppm));
        }