示例#1
0
        public void Register_Student_With_Non_Existing_Login_And_Good_Password_Success()
        {
            #region Arrange
            PersonRegisterViewModel newAccount = new PersonRegisterViewModel();
            newAccount.FirstMidName         = "Stu";
            newAccount.LastName             = "Stu";
            newAccount.Roles                = EnumRoles.Student;
            newAccount.Login                = "******";
            newAccount.Password             = "******";
            newAccount.PasswordConfirmation = "Stustu";

            BAL.StudentBAL bal = new BAL.StudentBAL();
            #endregion

            #region Act
            bal.CreateStudentRegistering(newAccount, dbContext);
            #endregion

            #region Assert


            Person stu = this.dbContext.Students.FirstOrDefault(e => e.Login == newAccount.Login);

            Assert.That(stu != null && stu.LastName == "Stu");
            #endregion
        }
示例#2
0
        public void Register_user_and_check_login_availaible_return_true()
        {
            #region Arrange
            PersonRegisterViewModel newAccount = new PersonRegisterViewModel();
            newAccount.FirstMidName         = "Account";
            newAccount.LastName             = "Account";
            newAccount.Roles                = EnumRoles.Student;
            newAccount.Login                = "******";
            newAccount.Password             = "******";
            newAccount.PasswordConfirmation = "Account";

            string loginToTest = "OtherLogin";

            BAL.StudentBAL balStudent = new BAL.StudentBAL();
            BAL.PersonBAL  balPerson  = new BAL.PersonBAL();
            #endregion

            #region Act
            balStudent.CreateStudentRegistering(newAccount, dbContext);
            #endregion

            #region Assert

            Assert.That(balPerson.IsLoginValid(loginToTest, dbContext) == true);
            #endregion
        }
示例#3
0
        public IHttpActionResult AddPerson([FromBody] PersonRegisterViewModel person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ValidationHelper.GenerateErrorMessage(ModelState.Values)));
            }

            return(Ok(_personService.AddPerson(person)));
        }
示例#4
0
        public IHttpActionResult CreateMainArtist(PersonRegisterViewModel mainArtist)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ValidationHelper.GenerateErrorMessage(ModelState.Values)));
            }

            return(Ok(_mainArtistService.AddMainArtist(mainArtist, User.Identity.Name)));
        }
示例#5
0
        public void Register_With_Existing_Login_Fail()
        {
            #region Arrange
            PersonRegisterViewModel newAccount1 = new PersonRegisterViewModel();

            #endregion



            Assert.That(false);
        }
示例#6
0
        public int AddMainArtist(PersonRegisterViewModel mainArtist, string user)
        {
            var partyRealPerson = _partyRealRepository.Get(pr => pr.fullname == mainArtist.Name || pr.uniqueidentifier == mainArtist.Ssn.Replace("-", ""));
            int newlyCreatedMainArtistId;

            if (partyRealPerson == null)
            {
                // Need to add person
                var newPersonId = _personService.AddPerson(mainArtist);
                newlyCreatedMainArtistId = AddMainArtistToDb(mainArtist, user, newPersonId);
            }
            else
            {
                // Need to connect already defined person with the main artist
                newlyCreatedMainArtistId = AddMainArtistToDb(mainArtist, user, partyRealPerson.id);
            }

            return(newlyCreatedMainArtistId);
        }
示例#7
0
        public void Register_Instructor_With_Non_Existing_Login_And_Good_Password_Success()
        {
            PersonRegisterViewModel newAccount = new PersonRegisterViewModel();

            newAccount.FirstMidName         = "Inst";
            newAccount.LastName             = "Inst";
            newAccount.Roles                = EnumRoles.Instructor;
            newAccount.Login                = "******";
            newAccount.Password             = "******";
            newAccount.PasswordConfirmation = "InstInst";

            BAL.InstructorBAL bal = new BAL.InstructorBAL();
            bal.CreateInstructorRegistering(newAccount, dbContext);

            Person inst = this.dbContext.Instructors.FirstOrDefault(e => e.Login == newAccount.Login);


            Assert.That(inst != null && inst.LastName == "Inst");
        }
示例#8
0
 public void CreateInstructorRegistering(PersonRegisterViewModel newAccount, SchoolContext db)
 {
     try
     {
         using (this.db)
         {
             Instructor newInstructor = new Instructor();
             newInstructor.LastName     = newAccount.LastName;
             newInstructor.FirstMidName = newAccount.FirstMidName;
             newInstructor.Login        = newAccount.Login;
             newInstructor.Password     = HashService.GenerateSHA256String(newAccount.Password);
             newInstructor.HireDate     = DateTime.Now;
             db.Instructors.Add(newInstructor);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#9
0
        public int AddPerson(PersonRegisterViewModel person)
        {
            var area   = _zipCodeRepository.Get(zc => zc.zipcode == person.Zipcode).areaname;
            var entity = new party_real
            {
                fullname           = person.Name,
                postaladdressline1 = person.Address,
                countrycode        = _countryRepository.GetById(person.NumericCountryIsoCode).twoletterisocode,
                zipcode            = person.Zipcode,
                uniqueidentifier   = person.Ssn.Replace("-", ""),
                area      = area,
                city      = area,
                deceased  = person.IsDeceased,
                updatedon = DateTime.Now
            };

            _partyRealRepository.Add(entity);
            _unitOfWork.Commit();

            return(entity.id);
        }
示例#10
0
 public void CreateStudentRegistering(PersonRegisterViewModel newAccount, SchoolContext db)
 {
     try
     {
         using (this.db)
         {
             Student newStudent = new Student();
             newStudent.LastName       = newAccount.LastName;
             newStudent.FirstMidName   = newAccount.FirstMidName;
             newStudent.Login          = newAccount.Login;
             newStudent.Password       = HashService.GenerateSHA256String(newAccount.Password);
             newStudent.EnrollmentDate = DateTime.Now;
             db.Students.Add(newStudent);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#11
0
        public ActionResult Add(PersonRegisterViewModel newAccount)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    PersonBAL balPerson = new PersonBAL();

                    if (balPerson.IsLoginValid(newAccount.Login, db))
                    {
                        if (newAccount.Roles == EnumRoles.Student)
                        {
                            StudentBAL balStudent = new StudentBAL();
                            balStudent.CreateStudentRegistering(newAccount, db);
                        }
                        else
                        {
                            InstructorBAL balInstructor = new InstructorBAL();
                            balInstructor.CreateInstructorRegistering(newAccount, db);
                        }
                        // Move searching of person in an other layer
                        //  getPersonByLogin(newAccount.Login)

                        Session["User"] = balPerson.GetPersonByLogin(newAccount.Login, db);
                        return(RedirectToAction(nameof(HomeController.Index), "Home"));
                    }
                    else
                    {
                        TempData["LoginError"] = "This login already exists";
                        return(RedirectToAction(nameof(AccountController.Register), "Account"));
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("Error", "Error");
            }
            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
示例#12
0
        private int AddMainArtistToDb(PersonRegisterViewModel mainArtist, string user, int newPersonId)
        {
            var entity = new party_mainartist
            {
                artistname     = mainArtist.Name,
                partyrealid    = newPersonId,
                artisttypecode = "SO",
                peformancetype = "M",
                genre          = "",
                website        = "",
                details        = "",
                externalid     = "0",
                updatedby      = user,
                updatedon      = DateTime.Now,
                createdby      = user,
                createdon      = DateTime.Now
            };

            _partyMainArtistRepository.Add(entity);
            _unitOfWork.Commit();

            return(entity.id);
        }