public static async Task <ServiceResponseResult> SendActivationEmailToTenant(int tenantId, string tenantEmail, string token, AddTenantToPropertyModel model)
        {
            var nvc = new NameValueCollection();

            nvc.Set("TenantId", tenantId.ToString());
            nvc.Set("Email", tenantEmail);
            nvc.Set("Token", token);
            nvc.Set("PropertyId", model.PropertyId.ToString());
            nvc.Set("StartDate1", model.StartDate.ToString());
            nvc.Set("EndDate1", model.EndDate.ToString());

            //nvc.Set("StartDate", model.StartDate. );
            //nvc.Set("EndDate", model.EndDate );
            nvc.Set("PaymentFrequencyId", model.PaymentFrequencyId.ToString());
            nvc.Set("PaymentAmount", model.PaymentAmount.ToString());
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/ActivateToBeTenant", UtilService.ToQueryString(nvc));
            string subject = "Property Community: Account Activation";
            string body    =
                "Hello !<br />"
                + $"You have registered to become a tenant at Property Community.<br />"
                + "Please <a target='_blank' href=" + url + "> Click Here </a> to activate<br />";
            MailMessage msg = new MailMessage()
            {
                Subject         = subject,
                SubjectEncoding = System.Text.Encoding.UTF8,
                Body            = body,
                BodyEncoding    = System.Text.Encoding.UTF8,
                IsBodyHtml      = true
            };

            msg.To.Add(tenantEmail);
            try
            {
                await EmailService.SendAsync(msg);

                return(new ServiceResponseResult {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponseResult {
                    IsSuccess = false
                });
            }
        }
        public static ServiceResponseResult ChangePasswordAfterLogin(ChangePasswordModel model, String login)
        {
            var result = new ServiceResponseResult
            {
                IsSuccess = false
            };

            using (var db = new KeysEntities())
            {
                try
                {
                    var currentUser = db.Login.FirstOrDefault(x => x.UserName == login);

                    if (currentUser == null)
                    {
                        result.ErrorMessage = "User is not found!";
                        return(result);
                    }
                    else
                    {
                        var salt         = UtilService.GeneratePassword(10, 5);
                        var passwordHash = AccountService.CreatePasswordHash(model.NewPassword, salt);
                        currentUser.PasswordHash       = passwordHash;
                        currentUser.SecurityStamp      = salt;
                        currentUser.ResetPasswordToken = "";
                        db.SaveChanges();
                        result.IsSuccess = true;
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    result.ErrorMessage = _serverError;
                    return(result);
                }
            }
        }
Esempio n. 3
0
        public static async Task <ServiceResponseResult> SendCreateAccountToTenant(PropertyMyOnboardModel model, string temPass, Person ownerPerson)
        {
            var    nvc     = new NameValueCollection();
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/Login");
            string subject = "Property Community: Acount Created By Landlord";
            string body    =
                "Hello !<br />"
                + $"{ownerPerson.FirstName} has added you to be a tenant in his/her property at Property Community.<br />"
                + "Your account details are as follow :<br />"
                + $"User name : {model.TenantToPropertyModel.TenantEmail}<br />"
                + $"Password : {temPass}<br />"
                + "Please <a target='_blank' href=" + url + "> Click Here </a> sign in.<br />";
            MailMessage msg = new MailMessage()
            {
                Subject         = subject,
                SubjectEncoding = System.Text.Encoding.UTF8,
                Body            = body,
                BodyEncoding    = System.Text.Encoding.UTF8,
                IsBodyHtml      = true
            };

            msg.To.Add(model.TenantToPropertyModel.TenantEmail);
            try
            {
                await SendAsync(msg);

                return(new ServiceResponseResult {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponseResult {
                    IsSuccess = false
                });
            }
        }
Esempio n. 4
0
        public static async Task <ServiceResponseResult> SendActivationEmailToTenant(PropertyMyOnboardModel model, Person ownerPerson)
        {
            var nvc = new NameValueCollection();

            nvc.Set("TenantEmail", model.TenantToPropertyModel.TenantEmail);
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/Login", UtilService.ToQueryString(nvc));
            string subject = "Property Community: Account Activated";
            string body    =
                "Hello !<br />"
                + $"{ownerPerson.FirstName} has added you to be a tenant in his/her property and activated your account on Property Community.<br />";

            MailMessage msg = new MailMessage()
            {
                Subject         = subject,
                SubjectEncoding = System.Text.Encoding.UTF8,
                Body            = body,
                BodyEncoding    = System.Text.Encoding.UTF8,
                IsBodyHtml      = true
            };

            msg.To.Add(model.TenantToPropertyModel.TenantEmail);
            try
            {
                await SendAsync(msg);

                return(new ServiceResponseResult {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new ServiceResponseResult {
                    IsSuccess = false
                });
            }
        }
        public static ServiceResponseResult CreateTenantAccount(AddTenantToPropertyModel model, Login creartor, string temPass)
        {
            using (var db = new KeysEntities())
            {
                var salt = UtilService.GeneratePassword(10, 5);
                //var temPass = UtilService.GeneraterRandomKey(8);
                var passwordHash = AccountService.CreatePasswordHash(temPass, salt);
                var login        = new Login
                {
                    UserName       = model.TenantEmail,
                    Email          = model.TenantEmail,
                    PasswordHash   = passwordHash,
                    SecurityStamp  = salt,
                    EmailConfirmed = true,
                    CreatedBy      = creartor.Email,
                    CreatedOn      = DateTime.Now,
                    IsActive       = true
                };

                var person = new Person
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Login     = login,
                    Address   = new Address
                    {
                        CountryId = 1,
                        IsActive  = true,
                    },
                    Address1 = new Address
                    {
                        CountryId = 1,
                        IsActive  = true
                    },

                    UID      = Guid.NewGuid(),
                    IsActive = true
                };
                var loginRole = new LoginRole
                {
                    RoleId          = 5,
                    IsActive        = true,
                    PendingApproval = false
                };
                db.Login.Add(login);
                person.Login = login;
                db.Person.Add(person);
                loginRole.Person = person;
                db.LoginRole.Add(loginRole);
                var tenant = new Tenant
                {
                    Person = person,
                    IsCompletedPersonalProfile = false,
                    HasProofOfIdentity         = false,
                    CreatedOn = DateTime.UtcNow,
                    CreatedBy = creartor.Id,
                    UpdatedOn = DateTime.UtcNow,
                    IsActive  = true,
                    Address   = new Address
                    {
                        CountryId = 1,
                        IsActive  = true,
                    }
                };
                db.Tenant.Add(tenant);
                try
                {
                    db.SaveChanges();
                    return(new ServiceResponseResult {
                        IsSuccess = true, NewObject = login
                    });
                }
                catch (Exception e)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false
                    });
                }
            }
        }
        public static ServiceResponseResult ChangePassword(ResetPasswordViewModel model, string HdToken)
        {
            var result = new ServiceResponseResult
            {
                IsSuccess = false
            };

            using (var db = new KeysEntities())
            {
                try
                {
                    var currentUser = db.Login.FirstOrDefault(x => x.UserName == model.Email && x.ResetPasswordToken == HdToken);
                    //if current doesn't exist or not active or disable
                    if (currentUser == null)
                    {
                        result.ErrorMessage = "Oops, Either you have clicked an expired link or the link as has tampered!";
                        return(result);
                    }
                    else
                    {
                        if (currentUser.ResetPasswordTokenExpiryDate < DateTime.Now)
                        {
                            result.ErrorMessage = "Your Account Reset password token has expired! Please do reset again";
                            return(result);
                        }
                        else
                        {
                            var salt         = UtilService.GeneratePassword(10, 5);
                            var passwordHash = AccountService.CreatePasswordHash(model.Password, salt);
                            //var newPasswordHash = AccountService.CreatePasswordHash(model.Password, currentUser.SecurityStamp);
                            currentUser.PasswordHash       = passwordHash;
                            currentUser.SecurityStamp      = salt;
                            currentUser.ResetPasswordToken = "";
                            db.SaveChanges();
                            result.IsSuccess = true;
                            return(result);
                        }
                    }
                    //if (currentUser.ResetPasswordTokenExpiryDate < DateTime.Now)
                    //{
                    //    result.ErrorMessage = "Your Account Reset password token has expired! Please do reset again";
                    //    return result;
                    //}
                    //generate new password hash from new password
                    //var salt = UtilService.GeneratePassword(10, 5);
                    //var passwordHash = AccountService.CreatePasswordHash(model.Password, salt);
                    ////var newPasswordHash = AccountService.CreatePasswordHash(model.Password, currentUser.SecurityStamp);
                    //currentUser.PasswordHash = passwordHash;
                    //currentUser.SecurityStamp = salt;
                    //currentUser.ResetPasswordToken = "";
                    //db.SaveChanges();
                    //result.IsSuccess = true;
                    //return result;
                }
                catch (Exception ex)
                {
                    result.ErrorMessage = _serverError;
                    return(result);
                }
            }
        }
Esempio n. 7
0
        public static async Task <bool> SendCreateAccountToTenantSendgrid(Person tenant, string email, string temPass, Person owner, string token, string address)
        {
            var nvc = new NameValueCollection();

            nvc.Set("token", token);
            nvc.Set("userId", tenant.Id.ToString());
            string             url  = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/Activate", UtilService.ToQueryString(nvc));
            SendGridEmailModel mail = new SendGridEmailModel
            {
                RecipentName  = tenant.FirstName,
                ButtonUrl     = url,
                RecipentEmail = email,
                NewUserName   = email,
                NewPassWord   = temPass,
                OwnerName     = owner.FirstName,
                Address       = address
            };

            try
            {
                await SendEmailWithSendGrid(EmailType.OwnerCreatNewTenantEmail, mail);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 8
0
        public static ServiceResponseResult AcceptQuote(JobAcceptedModel model, Login login)
        {
            using (var db = new KeysEntities())
            {
                var quote = db.JobQuote.FirstOrDefault(x => x.Id == model.QuoteId);
                if (quote == null)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = "Can note find quote"
                    });
                }
                quote.IsViewed = true;
                quote.Status   = "accepted";
                var job = new Job
                {
                    ProviderId     = quote.ProviderId,
                    PropertyId     = quote.TenantJobRequest.PropertyId,
                    AcceptedQuote  = quote.Amount,
                    JobDescription = model.JobDescription,
                    JobRequestId   = model.JobRequestId,
                    JobStatusId    = 2,
                    UpdatedBy      = login.Email,
                    CreatedOn      = DateTime.UtcNow,
                    UpdatedOn      = DateTime.UtcNow,
                    CreatedBy      = login.Email,
                    OwnerId        = login.Id
                };
                db.Job.Add(job);
                var marketJob = db.TenantJobRequest.FirstOrDefault(x => x.Id == model.JobRequestId);

                if (marketJob == null)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = "Can not find job!"
                    });
                }
                marketJob.JobStatusId = 5;
                var otherQuotes = db.JobQuote.Where(x => x.JobRequestId == model.JobRequestId && x.Id != model.QuoteId).ToList();
                otherQuotes.ForEach(x => x.Status = "unsuccessful");
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
                foreach (var item in otherQuotes)
                {
                    var nvc = new NameValueCollection();
                    nvc.Add("status", "unsuccessful");


                    string             url  = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Companies/Manage/MyQuotes", UtilService.ToQueryString(nvc));
                    SendGridEmailModel mail = new SendGridEmailModel
                    {
                        RecipentName  = item.ServiceProvider.Company.Name,
                        ButtonText    = "",
                        ButtonUrl     = url,
                        RecipentEmail = item.ServiceProvider.Company.CreatedBy,
                        JobTitle      = item.TenantJobRequest.JobDescription ?? "No Description",
                    };
                    EmailService.SendEmailWithSendGrid(EmailType.DeclineQuote, mail);
                }
                return(new ServiceResponseResult {
                    IsSuccess = true
                });
            }
        }