Exemplo n.º 1
0
        public string ResetPassword(int id)
        {
            string msg  = string.Empty;
            var    user = _context.AsQueryable <User>().Where(x => x.ID == id).FirstOrDefault();

            if (user != null)
            {
                try
                {
                    user.Password = ThreeDES.Encrypt("Password1");  //DEFAULT PASSWORD: Password1
                    _context.Update <User>(user);
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogsViewModel error = new LogsViewModel()
                    {
                        ActionType   = ActionType.Error.ToString(),
                        Description  = ex.Message + "\n" + ex.StackTrace,
                        ModifiedBy   = "User Service Error : ResetPassword()",
                        DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                    };
                    new LogsService().Create(error);
                    msg = "Unexpected error encountered. Please contact your system administrator.";
                }
            }

            return(msg);
        }
Exemplo n.º 2
0
        public string Create(UserViewModel model)
        {
            string msg = string.Empty;

            try
            {
                var ctr = _context.AsQueryable <User>().Where(x => x.Username == model.Username || x.Email == model.Email).Count();
                if (ctr > 0)
                {
                    msg = "Your profile email or username already exists.";
                }
                else
                {
                    User user = new User()
                    {
                        RoleID       = model.RoleID,
                        Username     = model.Username,
                        Password     = ThreeDES.Encrypt("Password1"),//DEFAULT PASSWORD: Password1
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        MiddleName   = model.MiddleName,
                        Email        = model.Email,
                        Address      = model.Address ?? "",
                        Phone        = model.Phone ?? "",
                        SSS          = model.SSS ?? "",
                        TIN          = model.TIN ?? "",
                        DateCreated  = DateTime.Now,
                        DateModified = DateTime.Now,
                        Active       = true
                    };
                    _context.Add <User>(user);
                    _context.SaveChanges();
                    msg = "New profile added.";
                }
            }
            catch (Exception ex)
            {
                LogsViewModel error = new LogsViewModel()
                {
                    ActionType   = ActionType.Error.ToString(),
                    Description  = ex.Message + "\n" + ex.StackTrace,
                    ModifiedBy   = "User Service Error : Create()",
                    DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                };
                new LogsService().Create(error);
                msg = "Unexpected error encountered. Please contact your system administrator.";
            }
            return(msg);
        }
Exemplo n.º 3
0
        public string Update(UserViewModel model)
        {
            string msg = string.Empty;

            try
            {
                User user     = _context.AsQueryable <User>().Where(x => x.ID == model.ID).FirstOrDefault();
                bool isExists = false;
                #region  check if current username and email is not equal to new value
                isExists = this.IsExists(user.ID, user.Username, model.Username, user.Email, model.Email);
                #endregion

                if (isExists)
                {
                    msg = "Your profile email or username already exists.";
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.Password))
                    {
                        user.Password = ThreeDES.Encrypt(model.Password);
                    }
                    if (!string.IsNullOrEmpty(model.Username))
                    {
                        user.Username = model.Username;
                    }
                    if (!string.IsNullOrEmpty(model.FirstName))
                    {
                        user.FirstName = model.FirstName;
                    }
                    if (!string.IsNullOrEmpty(model.LastName))
                    {
                        user.LastName = model.LastName;
                    }
                    if (!string.IsNullOrEmpty(model.MiddleName))
                    {
                        user.MiddleName = model.MiddleName;
                    }
                    if (!string.IsNullOrEmpty(model.Address))
                    {
                        user.Address = model.Address;
                    }
                    if (!string.IsNullOrEmpty(model.Phone))
                    {
                        user.Phone = model.Phone;
                    }
                    if (!string.IsNullOrEmpty(model.Email))
                    {
                        user.Email = model.Email;
                    }
                    if (!string.IsNullOrEmpty(model.SSS))
                    {
                        user.SSS = model.SSS;
                    }
                    if (!string.IsNullOrEmpty(model.TIN))
                    {
                        user.TIN = model.TIN;
                    }
                    if (model.RoleID != 0)
                    {
                        user.RoleID = model.RoleID;
                    }
                    user.DateModified = DateTime.Now;

                    if (user != null)
                    {
                        _context.Update <User>(user);
                        _context.SaveChanges();
                    }
                    msg = "Profile updated.";
                }
            }
            catch (Exception ex)
            {
                msg = "Unexpected error encountered. Please contact your system administrator.";
                LogsViewModel error = new LogsViewModel()
                {
                    ActionType   = ActionType.Error.ToString(),
                    Description  = ex.Message + "\n" + ex.StackTrace,
                    ModifiedBy   = "User Service Error : Update()",
                    DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                };
                new LogsService().Create(error);
            }
            return(msg);
        }