Beispiel #1
0
        public void Create(Entities.User obj)
        {
            // transaction scope
            using (var trans = new System.Transactions.TransactionScope())
            {
                // insert into Users
                Insert(obj);

                // UsersRole object
                Entities.UsersRole objUsersRole = new UsersRole();
                objUsersRole.RoleId = obj.RoleId;
                objUsersRole.Uid    = obj.Uid;

                // insert into UsersRole
                Rent.Business.Services.UserRole userRole = new UserRole();
                userRole.Insert(objUsersRole);

                // UsersPassword object
                Entities.UsersPassword objUsersPassword = new Entities.UsersPassword();
                objUsersPassword.Uid      = obj.Uid;
                objUsersPassword.Password = obj.UsersPassword.Password;

                // insert into UsersPassword
                Rent.Business.Services.UsersPassword usersPassword = new UsersPassword();
                usersPassword.Insert(objUsersPassword);

                // UsersNotification object
                Entities.UsersNotification objUsersNotification = new UsersNotification();
                objUsersNotification.Uid = obj.Uid;

                // insert into UsersNotification
                Rent.Business.Services.UserNotification userNotification = new UserNotification();
                userNotification.Insert(objUsersNotification);

                // into into UserAccessCode
                Rent.Business.Interfaces.IUserAccess iUserAccess = new UserAcess();
                iUserAccess.Insert(Rent.Common.Helper.Generator.AccessCode(), obj.Uid);

                // UsersManager
                if (obj.ManagerId > 0)
                {
                    Rent.Entities.UsersManager objUsersManager = new UsersManager();
                    objUsersManager.ManagerId = (int)obj.ManagerId;
                    objUsersManager.Uid       = obj.Uid;

                    // into into UsersUsersManager
                    Rent.Business.Interfaces.IUserManager iUserManager = new UserManager();
                    iUserManager.Insert(objUsersManager);
                }

                // commit transaction
                trans.Complete();
            }
        }
Beispiel #2
0
        public string ForgotPasswordEmail(Entities.User obj)
        {
            var r = "";

            try
            {
                using (var context = new RentEntities())
                {
                    var objPassword =
                        context.Users.FirstOrDefault(x => x.Email == obj.Email && x.Active);

                    if (objPassword == null)
                    {
                        r = "Email was not found. Please try again.";
                        return(r);
                    }

                    // password generate
                    var newPassword = Rent.Common.Helper.Generator.Password();

                    // set userPassword object
                    // call userPassword interface
                    Business.Interfaces.IUserPassword iUserPassword = new UsersPassword(new RentEntities());
                    var objUsersPassword = iUserPassword.Select(objPassword.Uid);
                    objUsersPassword.Password = newPassword;
                    iUserPassword.Update(objUsersPassword);

                    const string  subject       = "Rental Payment - New Password";
                    StringBuilder stringBuilder = new StringBuilder();

                    stringBuilder.Append("Hello " + objPassword.Name + ",");
                    stringBuilder.Append("<p>Your temporary password is: </br> " + newPassword);
                    stringBuilder.Append("</br></br>");
                    stringBuilder.Append("We encourage you to create a password you can easily remember. </br>");

                    stringBuilder.Append("You can login with your information here: " +
                                         Rent.Business.Properties.Settings.Default.Host + " to view your account.");
                    stringBuilder.Append("</br> ");

                    // send email
                    var i = Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(obj.Email), subject,
                                                                  stringBuilder.ToString(), true);

                    var j = Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, obj.Email);

                    // send text message
                    if (obj.Phone != null)
                    {
                        foreach (var source in Rent.Common.Helper.Carriers.SelectMobileCarriers(obj.Phone))
                        {
                            i =
                                +Rent.Common.Helper.Email.MlfusionSmtp(new MailAddress(source), subject,
                                                                       stringBuilder.ToString(), false);

                            // insert into LogEmail
                            j = +Business.Services.LogEmail.Insert(stringBuilder, obj.Uid, source);
                        }
                    }

                    r = i > 0
                        ? "Login credentials has been emailed to you."
                        : "Sorry, the web service is down. Please try again later.";
                }
            }
            catch (Exception exception)
            {
                Business.Services.LogError.Insert(exception, 0);
                r = "Error: " + exception.Message;
            }

            return(r);
        }