// POST api/<controller>
        public async Task <string> Post(RegistrationView value)
        {
            var result = "Success";
            NHibernateCompanyStore store = new NHibernateCompanyStore();
            NHibernateUserStore    user  = new NHibernateUserStore();
            PasswordHasher         ph    = new PasswordHasher();
            var passHash = ph.HashPassword(value.password);
            var emp      = new EmployeeModel()
            {
                FirstName  = value.FirstName,
                LastName   = value.LastName,
                Email      = value.Email,
                EmpNo      = value.EmpNo,
                Contact    = value.Contact,
                Gender     = value.Gender,
                Company    = await store.GetCompanyByIdAsync(value.CompanyId),
                Team       = await store.GetTeamByIdAsync(value.TeamId),
                position   = await store.GetPositionByIdAsync(value.Job_Id),
                Department = await store.GetDepartmentByIdAsync(value.Dept_Id)
            };
            //var employee=await store.RegisterEmployeeAsync(emp);
            var usr = new UserModel()
            {
                UserName     = value.Email,
                FirstName    = value.FirstName,
                LastName     = value.LastName,
                PasswordHash = passHash,
                employee     = emp
            };
            await user.CreateAsync(usr);

            return(result);
        }
        public async Task <bool> RegisterUser(UserModel user)
        {
            NHibernateUserStore store = new NHibernateUserStore();
            var usr = await store.FindByNameAsync(user.UserName);

            if (usr == null)
            {
                await store.CreateAsync(user);

                return(true);
            }
            return(false);
        }
Exemple #3
0
        // POST api/<controller>
        public async Task <string> Post(RegistrationSatusModel value)
        {
            string    id     = null;
            string    result = "Ok";
            var       nus    = new NHibernateUserStore();
            UserModel user   = null;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                id = HttpContext.Current.Session["UserId"].ToString();
            }
            if (id == null)
            {
                user = await nus.FindByStampAsync(CurrentUserSession.userSecurityStampCookie);
            }
            else
            {
                user = await nus.FindByIdAsync(id);
            }

            var nds = new NHibernateDriverStore();

            var driver       = nds.FindByIdAsync(value.Id).Result;
            var existingUser = await nus.FindByNameAsync(driver.Email);

            driver.Status    = RegistrationStatus.Accepted;
            driver.UpdatedBy = user;
            if (existingUser != null)
            {
                existingUser.Driver = driver;
                await nus.UpdateAsync(existingUser);
            }
            else
            {
                var usr = new UserModel {
                    UserName      = driver.Email,
                    FirstName     = driver.FirstName,
                    LastName      = driver.LastName,
                    PasswordHash  = driver.Password,
                    SecurityStamp = Guid.NewGuid().ToString(),
                    Driver        = driver
                };
                await nus.CreateAsync(usr);
            }
            var emails = driver.Email;
            await Emailer.SendMessage(driver.Email + " Activated", emails, "Registration");

            return(result);
        }
        // POST api/<controller>
        public async Task <string> Post(PassengerModel value)
        {
            string         result    = "Ok";
            PasswordHasher ph        = new PasswordHasher();
            var            passHash  = ph.HashPassword(value.Password);
            var            hps       = new NHibernatePassengerStore();
            var            passenger = new PassengerModel {
                Email        = value.Email,
                FirstName    = value.FirstName,
                LastName     = value.LastName,
                MiddleName   = value.MiddleName,
                BirthDate    = value.BirthDate,
                Gender       = value.Gender,
                Town         = value.Town,
                Province     = value.Province,
                City         = value.City,
                MobileNumber = value.MobileNumber,
                Password     = passHash
            };
            var nhus         = new NHibernateUserStore();
            var existingUser = await nhus.FindByNameAsync(passenger.Email);

            try {
                if (existingUser != null)
                {
                    existingUser.Passenger = passenger;
                    await nhus.UpdateAsync(existingUser);
                }
                else
                {
                    var usr = new UserModel {
                        UserName      = passenger.Email,
                        FirstName     = passenger.FirstName,
                        LastName      = passenger.LastName,
                        PasswordHash  = passenger.Password,
                        SecurityStamp = Guid.NewGuid().ToString(),
                        Passenger     = passenger
                    };
                    await nhus.CreateAsync(usr);
                }
            } catch (Exception e) {
                result = e.Message;
            }
            return(result);
        }