Esempio n. 1
0
        public static User Map(this tblUsers user)
        {


            User usr = new User(user.Id)
                           {
                               Username = user.UserName,
                               Password = user.Password,
                               PIN = user.PIN,
                               Mobile = user.Mobile,
                               CostCentre = user.CostCenterId,
                               UserType = (UserType) user.UserType,
                               Group = user.tblUserGroup.Map(),
 
            };
            List<UserRole> roles = new List<UserRole>();
            if(usr.Group!=null)
            {
                foreach(UserGroupRoles role in  user.tblUserGroup.tblUserGroupRoles.Where(v=>v.CanAccess).Select(s=>s.Map()).ToList())
                {
                    usr.UserRoles.Add(role.UserRole.ToString());
                }
            }
            if (user.TillNumber != null)
                usr.TillNumber =user.TillNumber;
            usr._SetDateCreated(user.IM_DateCreated);
            usr._SetDateLastUpdated(user.IM_DateLastUpdated.Value);
            usr._SetStatus((EntityStatus)user.IM_Status);
            return usr;
        }
Esempio n. 2
0
        public bool RegisterSuperAdmin(User user)
        {
            user._SetStatus(EntityStatus.Active);
            var group = _userGroupRepository.GetAll().FirstOrDefault(s => s.Name == "Admin");
            Guid userGroupID;
            if (group == null)
            {
                userGroupID = AddUserGroup("Admin");
                AddUserGroupRoles(userGroupID);
            }
            else
            {
                userGroupID = group.Id;
            }
            if (userGroupID == Guid.Empty)
                throw new DomainValidationException(new ValidationResultInfo(),
                                                    "Unable to create user group " + "Admin");


            var existing = _userRepository.GetAll().FirstOrDefault(s => s.Username == user.Username);
            if(existing!=null)
            {
                user.Id = existing.Id;
            }
            user.Group = _userGroupRepository.GetById(userGroupID);


            Guid adminId = _userRepository.Save(user);
            if (adminId == Guid.Empty)
                throw new DomainValidationException(new ValidationResultInfo(),
                                                    "Unable to create super admin " + user.Username);
            return true;
        }
Esempio n. 3
0
        protected Guid AddUser(string Username, string password, string mobile, string pin, Guid costCenter, UserType usertype, Guid groupId)
        {
            User usr = new User(Guid.NewGuid())
            {
                Username = Username,
                Password =EncryptorMD5.GetMd5Hash(password),
                Mobile = mobile,
                PIN = pin,
                UserType = usertype,
                CostCentre = costCenter,
                Group = _userGroupRepository.GetById(groupId),
                

            };
            usr._SetStatus(EntityStatus.Active);
            return _userRepository.Save(usr);
        }
        User AddUser(string username, Guid costCenter, UserType usertype, Guid groupId)
        {
            var userrepo = ObjectFactory.GetInstance<IUserRepository>();
            var tbluser= ObjectFactory.GetInstance<CokeDataContext>().tblUsers.FirstOrDefault(
                p => p.UserName.ToLower() == username.ToLower() && p.UserType == (int) usertype);
            if (tbluser != null)
                return userrepo.GetById(tbluser.Id);

            var usr = new User(Guid.NewGuid())
            {
                Username = username,
                Password = EncryptorMD5.GetMd5Hash("12345678"),
                Mobile = "07000000",
                PIN = "",
                UserType = usertype,
                CostCentre = costCenter,
                Group = ObjectFactory.GetInstance<IUserGroupRepository>().GetById(groupId),


            };
            usr._SetStatus(EntityStatus.Active);
           userrepo.Save(usr);
            return userrepo.GetById(usr.Id);
        }