public void CreateBusinessUser(BusinessUserDTO newBusinessUser)
        {
            string sql = @"insert into dbo.BusinessUser (BusinessName, UserName, Password, Email, Info, Sector)
                          values(@BusinessName, @UserName, @Password, @Email, @Info, @Sector);";

            _dBManager.SaveData(sql, newBusinessUser);
        }
        public BusinessRegistration Validate()
        {
            //  Method to validate a new business user

            BusinessUserDTO existingBusinessUser = _businessUserDAL.CheckBusinessUserNameEmailName(UserName, Email, BusinessName).FirstOrDefault();

            BusinessRegistration _registerValidation = new BusinessRegistration();

            if (existingBusinessUser == null)
            {
                _registerValidation.Valid = true;
            }
            else
            {
                if (existingBusinessUser.UserName.ToLower() == UserName.ToLower())
                {
                    _registerValidation.UserNameError = true;
                }
                if (existingBusinessUser.Email.ToLower() == Email.ToLower())
                {
                    _registerValidation.EmailError = true;
                }
                if (existingBusinessUser.BusinessName.ToLower() == BusinessName.ToLower())
                {
                    _registerValidation.BusinessNameError = true;
                }
            }

            return(_registerValidation);
        }
        public int GetBusinessId(string userName)
        {
            string sql = $"select Id from dbo.BusinessUser where (UserName = @userName);";

            var dictionary = new Dictionary <string, object>
            {
                { "@userName", userName }
            };


            var parameters = new DynamicParameters(dictionary);

            BusinessUserDTO businessUserDTO = _dBManager.LoadData <BusinessUserDTO>(sql, parameters).FirstOrDefault();

            if (businessUserDTO != null)
            {
                try
                {
                    return(businessUserDTO.Id);
                }
                catch
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new Exception();
            }
        }
 public BusinessUserModel(BusinessUserDTO businessUserDTO)
 {
     Id           = businessUserDTO.Id;
     BusinessName = businessUserDTO.BusinessName;
     UserName     = businessUserDTO.UserName;
     Password     = businessUserDTO.Password;
     Email        = businessUserDTO.Email;
     Info         = businessUserDTO.Info;
     Sector       = businessUserDTO.Sector;
 }
Esempio n. 5
0
        public void UpdateUser(int businessId, BusinessUserDTO dto)
        {
            // if only one admin left, then don't update the role?

            BusinessUser businessUser = _ctx.BusinessUsers.SingleOrDefault(b => b.BusinessId == businessId && b.UserId == dto.User.Id);

            if (businessUser != null)
            {
                businessUser.Role  = dto.Role;
                businessUser.Title = dto.Title;

                _ctx.SaveChanges();
            }
        }
        public void UpdateInfo(string info)
        {
            BusinessUserDTO updatedBusinessUserDTO = new BusinessUserDTO
            {
                Id           = Id,
                BusinessName = BusinessName,
                UserName     = UserName,
                Password     = Password,
                Email        = Email,
                Info         = info,
                Sector       = Sector
            };

            _businessUserDAL.UpdateInfo(updatedBusinessUserDTO);
        }
Esempio n. 7
0
        public Result UpdateUser(int businessId, BusinessUserDTO businessUser)
        {
            Business business = _businessRepository.GetBusiness(businessId);

            if (business.IsStaffInRole(UserId, UserRole.Admin) || IsSuperUser)
            {
                _businessRepository.UpdateUser(businessId, businessUser);
                Result result = new Result(true);
                return(result);
            }

            return(new Result(false)
            {
                Message = "not admin"
            });
        }
        public void CreateBusinessUser(BusinessUserModel newBusinessUser)
        {
            //  Creates new business user

            BusinessUserDTO newBusinessUserDTO = new BusinessUserDTO
            {
                BusinessName = newBusinessUser.BusinessName,
                UserName     = newBusinessUser.UserName,
                Password     = newBusinessUser.Password,
                Email        = newBusinessUser.Email,
                Info         = newBusinessUser.Info,
                Sector       = newBusinessUser.Sector
            };

            _BusinessUserCollectionDAL.CreateBusinessUser(newBusinessUserDTO);
        }
Esempio n. 9
0
        public void AddUser(int businessId, BusinessUserDTO dto)
        {
            //Business business = _ctx.Businesses.Include("BusinessUsers").SingleOrDefault(b => b.Id == businessId);
            Business business = _ctx.Businesses.SingleOrDefault(b => b.Id == businessId);
            User     user     = _ctx.Users.Find(dto.User.Id);

            if (business != null && user != null)
            {
                BusinessUser businessUser = new BusinessUser()
                {
                    Business = business, User = user, Role = dto.Role, Title = dto.Title
                };

                _ctx.BusinessUsers.Add(businessUser);
                _ctx.SaveChanges();
            }
        }
Esempio n. 10
0
        public Result AddUser(int businessId, BusinessUserDTO businessUser)
        {
            Business business = _businessRepository.GetBusiness(businessId);

            if (business.IsStaffInRole(UserId, UserRole.Admin) || IsSuperUser)
            {
                if (!business.BusinessUsers.Any(bu => bu.UserId == businessUser.User.Id))
                {
                    _businessRepository.AddUser(businessId, businessUser);
                    Result result = new Result(true);
                    return(result);
                }

                return(new Result(false)
                {
                    Message = "already added"
                });
            }

            return(new Result(false)
            {
                Message = "not admin"
            });
        }
 public void UpdateBusinessUser(BusinessUserDTO updatedBusinessUser)
 {
     string sql = $"";
 }
 public void UpdateInfo(BusinessUserDTO updatedBusinessUserDTO)
 {
 }