private String StringifyContent(UserAlertDTO document, String content)
        {
            String result = content;

            result = result.Replace("{{CompanyName}}", document.CompanyName);
            result = result.Replace("{{Username}}", document.Username);
            result = result.Replace("{{TemporaryPassword}}", document.TemporaryPassword);
            return(result);
        }
        public void ResetPasswordByEmail(string Email)
        {
            string companyName       = "";
            string username          = "";
            string temporaryPassword = "";
            string email             = "";
            User   user = (from u in _unitOfWork.User.FindAll().Where(u => u.Email == Email && u.Active == true) select u).FirstOrDefault();

            if (user != null)
            {
                companyName              = user.Company.Name;
                username                 = user.Username;
                email                    = user.Email;
                temporaryPassword        = Utility.GenerateRandomPassword();
                user.Password            = temporaryPassword;
                user.PasswordChangedDate = DateTime.Now;
                user.ModifiedBy          = user.Username;
                user.ModifiedDate        = DateTime.Now;

                _unitOfWork.User.Update(user);
                _unitOfWork.SaveChanges();

                // Create Alert
                UserAlertDTO document = new UserAlertDTO();
                document.Username          = username;
                document.TemporaryPassword = temporaryPassword;
                document.CompanyName       = companyName;
                document.UserEmail         = email;
                AlertMaster alert        = (from a in _unitOfWork.AlertMaster.FindAll().Where(a => a.Code == "RP" && a.Active == true) select a).FirstOrDefault();
                string      emailFrom    = alert.EmailFrom;
                string      emailSubject = StringifyContent(document, alert.EmailSubject);
                string      emailContent = StringifyContent(document, alert.EmailContent);
                string      emailTo      = StringifyContent(document, alert.EmailTo);

                Utility.SendEmail("192.168.1.20", emailFrom, emailTo, "", emailSubject, emailContent);
            }
        }
        public void ChangePassword(UserPasswordDTO userPasswordDTO)
        {
            string companyName = "";
            string username    = "";
            string newPassword = "";
            string email       = "";
            User   user        = (from u in _unitOfWork.User.FindAll().Where(u => u.Username == userPasswordDTO.Username && u.Password == userPasswordDTO.OldPassword && u.Active == true) select u).FirstOrDefault();

            if (user != null)
            {
                companyName              = user.Company.Name;
                username                 = user.Username;
                email                    = user.Email;
                newPassword              = userPasswordDTO.NewPassword;
                user.Password            = newPassword;
                user.PasswordChangedDate = DateTime.Now;
                user.ModifiedBy          = user.Username;
                user.ModifiedDate        = DateTime.Now;

                _unitOfWork.User.Update(user);
                _unitOfWork.SaveChanges();

                // Create Alert
                UserAlertDTO document = new UserAlertDTO();
                document.Username    = username;
                document.CompanyName = companyName;
                document.UserEmail   = email;
                AlertMaster alert        = (from a in _unitOfWork.AlertMaster.FindAll().Where(a => a.Code == "CP" && a.Active == true) select a).FirstOrDefault();
                string      emailFrom    = alert.EmailFrom;
                string      emailSubject = StringifyContent(document, alert.EmailSubject);
                string      emailContent = StringifyContent(document, alert.EmailContent);
                string      emailTo      = StringifyContent(document, alert.EmailTo);

                Utility.SendEmail("192.168.1.20", emailFrom, emailTo, "", emailSubject, emailContent);
            }
        }