public ModelViewUser Update(ModelViewUser model)
        {
            var objRepository = new RepositoryUser();

            var dataOld = new RepositoryUser().Get(model.UserID);

            EntityUser data = new EntityUser()
            {
                UserID           = model.UserID,
                ProfileID        = model.ProfileID,
                UserName         = model.UserName,
                Name             = model.Name,
                Password         = dataOld.Password,
                Token            = dataOld.Token,
                ChangePassword   = dataOld.ChangePassword,
                Email            = model.Email,
                Status           = dataOld.Status,
                DateLastAccess   = dataOld.DateLastAccess,
                DateCreate       = dataOld.DateCreate,
                DateModification = DateTime.UtcNow
            };

            data = objRepository.Update(data);

            return(model);
        }
        public ModelViewUser Get(int UserID)
        {
            ModelViewUser result = new ModelViewUser();
            var           data   = new RepositoryUser().Get(UserID);

            result.Email       = data.Email;
            result.Name        = data.Name;
            result.ProfileID   = data.ProfileID;
            result.FK_ModuleID = data.ModuleID;
            result.UserID      = data.UserID;
            result.UserName    = data.UserName;
            return(result);
        }
Esempio n. 3
0
        public ModelViewUser Authenticate(string UserName, string Password)
        {
            ModelViewUser result = null;

            var dataUsuario = new RepositoryUser().GetUserName(UserName);

            if (dataUsuario == null)
            {
                throw new Exception("UserPasswordInvalid");
            }

            if (dataUsuario.Password != new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(Password))
            {
                throw new Exception("UserPasswordInvalid");
            }

            if (!dataUsuario.Status)
            {
                throw new Exception("UserInvalid");
            }

            result = new ModelViewUser()
            {
                UserID         = dataUsuario.UserID,
                Name           = dataUsuario.Name,
                Token          = dataUsuario.Token,
                ProfileID      = dataUsuario.ProfileID,
                ChangePassword = dataUsuario.ChangePassword,
                Email          = dataUsuario.Email,
                UserName       = dataUsuario.UserName,
                Profile        = new RepositoryProfile().Get(dataUsuario.ProfileID).Profile,
                EmployeeStore  = new BusinessEmployee().GetEmployeeStore(dataUsuario.UserID)
            };

            return(result);
        }
        public ModelViewUser Insert(ModelViewUser model)
        {
            var objRepository = new RepositoryUser();
            var objSecurity   = new BusinessSecurity();

            bool   salir = false;
            string token = "";

            while (!salir)
            {
                token = objSecurity.GenerateToken();
                if (objRepository.GetToken(token) == null)
                {
                    salir = true;
                }
            }
            string clave = objSecurity.GeneratePassword(8);

            if (objRepository.GetEmail(model.Email) != null)
            {
                throw new Exception("DuplicateEmail");
            }

            if (objRepository.GetUserName(model.UserName) != null)
            {
                throw new Exception("DuplicateUser");
            }


            EntityUser data = new EntityUser()
            {
                UserID           = model.UserID,
                ProfileID        = model.ProfileID,
                UserName         = model.UserName,
                Name             = model.Name,
                Password         = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(clave),
                Token            = token,
                ChangePassword   = true,
                Email            = model.Email,
                Status           = true,
                DateLastAccess   = DateTime.UtcNow,
                DateCreate       = DateTime.UtcNow,
                DateModification = DateTime.UtcNow
            };

            data = objRepository.Insert(data);

            model.UserID = data.UserID;

            List <string> arr = new List <string>();

            arr.Add(model.Email);

            string sb = File.ReadAllText(GlobalConfiguration.LocateBodyMail + "NotificationUserBodyContent.txt");

            sb = sb.Replace("#%NombreUsuario%#", data.UserName);
            sb = sb.Replace("#%ClaveTemporal%#", clave);
            sb = sb.Replace("#%Nombre%#", data.Name);
            //Nombre de usuario, usuario, pass,
            //new BusinessNotification().SendMails(arr, "Mabe - Registro de usuario ServiPlus", sb);
            new BusinessNotification().SendMailExchange(GlobalConfiguration.exchangeUser, GlobalConfiguration.exchangePwd, arr, "Mabe - Registro de usuario ServiPlus", sb);
            return(model);
        }
Esempio n. 5
0
        public ModelViewUser Authenticate(ModelViewLogin model)
        {
            ModelViewUser result = null;

            var dataUsuario = new RepositoryUser().GetUserName(model.UserName);

            if (model.Token != GlobalConfiguration.TokenWEB)
            {
                if (model.Token != GlobalConfiguration.TokenMobile)
                {
                    throw new Exception("TokenInvalid");
                }
            }

            if (dataUsuario == null)
            {
                throw new Exception("UserPasswordInvalid");
            }

            if (dataUsuario.ProfileID == 4 && model.Origin == "WEB")
            {
                throw new Exception("NoAccess");
            }

            var x = new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.Password);

            if (dataUsuario.Password != new BusinessCryptoMD5(GlobalConfiguration.CryptoKey).CryptoString(model.Password))
            {
                throw new Exception("UserPasswordInvalid");
            }

            if (!dataUsuario.Status)
            {
                throw new Exception("UserInvalid");
            }
            if (dataUsuario.ModuleID != null)
            {
                var module = new BusinessModuleService().GetAllBYModule(dataUsuario.ModuleID.Value);
                result = new ModelViewUser()
                {
                    UserID         = dataUsuario.UserID,
                    Name           = dataUsuario.Name,
                    Token          = dataUsuario.Token,
                    ProfileID      = dataUsuario.ProfileID,
                    ChangePassword = dataUsuario.ChangePassword,
                    Email          = dataUsuario.Email,
                    UserName       = dataUsuario.UserName,
                    Profile        = new RepositoryProfile().Get(dataUsuario.ProfileID).Profile,
                    EmployeeStore  = new BusinessEmployee().GetEmployeeStore(dataUsuario.UserID),
                    LatWorkshop    = module.LatWorkshop,
                    LongWorkshop   = module.LongWorkshop
                };
            }
            else
            {
                result = new ModelViewUser()
                {
                    UserID         = dataUsuario.UserID,
                    Name           = dataUsuario.Name,
                    Token          = dataUsuario.Token,
                    ProfileID      = dataUsuario.ProfileID,
                    ChangePassword = dataUsuario.ChangePassword,
                    Email          = dataUsuario.Email,
                    UserName       = dataUsuario.UserName,
                    Profile        = new RepositoryProfile().Get(dataUsuario.ProfileID).Profile,
                    EmployeeStore  = new BusinessEmployee().GetEmployeeStore(dataUsuario.UserID),
                    LatWorkshop    = 0,
                    LongWorkshop   = 0
                };
            }



            return(result);
        }
Esempio n. 6
0
 public static ModelViewUser Update(ModelViewUser model)
 {
     return(new BusinessUsers().Update(model));
 }
Esempio n. 7
0
 public static ModelViewUser Insert(ModelViewUser model)
 {
     return(new BusinessUsers().Insert(model));
 }