Exemple #1
0
        public JsonResult AddTenant(FinancialModel model)
        {
            AddTenantToPropertyModel tenant = new AddTenantToPropertyModel();
            var user  = User.Identity.Name;
            var login = AccountService.GetLoginByEmail(user);
            var ten   = AccountService.GetLoginByEmail(model.TenantToPropertyModel.TenantEmail);

            if (ten == null)
            {
                tenant.TenantEmail        = model.TenantToPropertyModel.TenantEmail;
                tenant.StartDate          = model.TenantToPropertyModel.StartDate;
                tenant.EndDate            = model.TenantToPropertyModel.EndDate;
                tenant.PaymentAmount      = model.TenantToPropertyModel.PaymentAmount;
                tenant.PaymentFrequencyId = model.TenantToPropertyModel.PaymentFrequencyId;
                tenant.PropertyId         = model.PropId;

                //var TenantEmailResult = SendInvitationEmailToTenant(tenant);

                return(Json(new { Success = false, NewPropId = model.PropId, Todo = "Send email", ErrorMsg = "Cannot find person in login table!" }));
            }
            else
            {
                var person = AccountService.GetPersonByLoginId(ten.Id);
                var result = PropertyService.AddTenantToProperty(login, person.Id, model.PropId, model.TenantToPropertyModel.StartDate,
                                                                 model.TenantToPropertyModel.EndDate, model.TenantToPropertyModel.PaymentFrequencyId, model.TenantToPropertyModel.PaymentAmount);
                if (result.IsSuccess)
                {
                    return(Json(new { Sucess = true, Msg = "Added!", result = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                }
                else
                {
                    return(Json(new { Sucess = false, Msg = result.ErrorMessage, redirect = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                }
            }
        }
Exemple #2
0
        public async Task <ActionResult> SendInvitationEmailToTenant(AddTenantToPropertyModel model)
        {
            var user = User.Identity.Name;

            if (String.IsNullOrEmpty(user))
            {
                return(Json(new { Success = false, ErrorMsg = "Invalid user!" }));
            }
            var owner = AccountService.GetLoginByEmail(user);

            if (owner == null)
            {
                return(Json(new { Success = false, ErrorMsg = "Can not find current user!" }));
            }
            var ownerPerson = AccountService.GetPersonByLoginId(owner.Id);
            var property    = PropertyService.GetPropertyById(model.PropertyId);

            if (property == null)
            {
                return(Json(new { Success = false, ErrorMsg = "Can not find property!" }));
            }
            var nvc = new NameValueCollection();

            nvc.Set("TenantEmail", model.TenantEmail);
            nvc.Set("PropertyId", model.PropertyId.ToString());
            nvc.Set("StartDate", model.StartDate.ToString());
            nvc.Set("EndDate", model.EndDate.ToString());
            nvc.Set("PaymentFrequencyId", model.PaymentFrequencyId.ToString());
            nvc.Set("PaymentAmount", model.PaymentAmount.ToString());
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/RegisterToBeTenant", UtilService.ToQueryString(nvc));
            string subject = "Property Community: Invitation to register";
            string body    =
                "Hello !<br />"
                + $"{ownerPerson.FirstName} has added you to be a tenant in his/her property and invited you to register at Property Community.<br />"
                + $"name has added you to be a tenant in his/her property and invited you to register at Property Community.<br />"

                + "Please <a target='_blank' href=" + url + "> Click Here </a> to register<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.TenantEmail);
            try
            {
                await EmailService.SendAsync(msg);

                return(Json(new { Success = true, Status = "Await response" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = false, msg = ex.ToString() }));
            }
        }
Exemple #3
0
        public JsonResult AddTenantToProperty(AddTenantToPropertyModel model)
        {
            var user   = User.Identity.Name;
            var login  = AccountService.GetLoginByEmail(user);
            var tenant = AccountService.GetLoginByEmail(model.TenantEmail);

            if (tenant == null)
            {
                var temPass   = UtilService.GeneraterRandomKey(8);
                var createRes = AccountService.CreateTenantAccount(model, login, temPass);

                if (!createRes.IsSuccess)
                {
                    tenant = createRes.NewObject as Login;
                    return(Json(new { Success = false, NewPropId = model.Id }));
                }
            }
            var newTenantProperty = new TenantProperty
            {
                Id                 = model.Id,
                TenantId           = tenant.Id,
                CreatedBy          = User.Identity.Name,
                CreatedOn          = DateTime.Now,
                UpdatedBy          = User.Identity.Name,
                UpdatedOn          = DateTime.Now,
                StartDate          = model.StartDate,
                EndDate            = model.EndDate,
                PaymentAmount      = model.PaymentAmount,
                PaymentFrequencyId = model.PaymentFrequencyId,
                PropertyId         = model.PropertyId,
                PaymentStartDate   = model.PaymentStartDate,
                PaymentDueDate     = model.PaymentDueDate,
                IsMainTenant       = model.IsMainTenant,
                IsActive           = tenant.IsActive
            };

            if (model.Liabilities != null)
            {
                model.Liabilities.ForEach(x =>
                {
                    db.TenantPropertyLiability.Add(new TenantPropertyLiability
                    {
                        LiabilityName  = x.Name,
                        Amount         = x.Amount,
                        TenantProperty = newTenantProperty
                    });
                });
            }

            db.TenantProperty.Add(newTenantProperty);
            db.SaveChanges();
            return(Json(new { Success = true, NewId = newTenantProperty.Id }));
        }
        public async Task <ActionResult> SendCreateAccountEmailToTenant(AddTenantToPropertyModel model, LoginViewModel loginModel)
        {
            var user = User.Identity.Name;

            if (String.IsNullOrEmpty(user))
            {
                return(Json(new { Success = false, ErrorMsg = "Invalid user!" }));
            }
            var owner = AccountService.GetLoginByEmail(user);

            if (owner == null)
            {
                return(Json(new { Success = false, ErrorMsg = "Can not find current user!" }));
            }
            var ownerPerson = AccountService.GetPersonByLoginId(owner.Id);
            var property    = PropertyService.GetPropertyById(model.PropertyId);

            if (property == null)
            {
                return(Json(new { Success = false, ErrorMsg = "Can not find property!" }));
            }
            var    nvc     = new NameValueCollection();
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/Login");
            string subject = "Property Community: Invitation to register";
            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 : {loginModel.UserName}<br />"
                + $"Password : {loginModel.Password}"
                + "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.TenantEmail);
            try
            {
                await EmailService.SendAsync(msg);

                return(Json(new { Success = true, Status = "Await response" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = false, msg = ex.ToString() }));
            }
        }
        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 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
                });
            }
        }
Exemple #7
0
        public async Task <JsonResult> AddNewProperty(PropertyMyOnboardModel model)
        {
            var files   = Request.Files;
            var status  = true;
            var message = "Record added successfully";
            var data    = model;
            AddTenantToPropertyModel tenant = new AddTenantToPropertyModel();
            var user         = User.Identity.Name;
            var login        = AccountService.GetLoginByEmail(user);
            var newProp      = PropertyOwnerService.AddOnboardProperty(login, model);
            var newRepayment = new PropertyRepayment();

            if (newProp == null)
            {
                return(Json(new { Success = false, message = "Cannot add the property!" }));
            }
            else
            {
                newRepayment = PropertyOwnerService.AddOnboardRepayment(login, model.Repayments, newProp.Id);
                decimal _totalRepayment = 0;
                int     _nosWeeks       = 0;
                int     _nosFortnights  = 0;
                int     _nosMonthly     = 0;
                if (newRepayment != null)
                {
                    foreach (Service.Models.RepaymentViewModel repayment in model.Repayments)
                    {
                        switch (repayment.FrequencyType)
                        {
                        case 1:     // Weekly
                                    // find the nos of weeks in datediff(StartDate, EndDate)
                            _nosWeeks = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 7;
                            // _totalAmount = nos weeks * amount
                            _totalRepayment = _nosWeeks * newRepayment.Amount;
                            break;

                        case 2:       // Fortnightly
                                      // find the nos of Fortnights in datediff(StartDate, EndDate)
                            _nosFortnights = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 14;
                            // _totalAmount = nos weeks * amount
                            _totalRepayment = _nosFortnights * newRepayment.Amount;
                            break;

                        case 3:     //Monthly
                                    // find the nos of Monthls in datediff(StartDate, EndDate)
                            _nosMonthly     = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 30;
                            _totalRepayment = _nosMonthly * newRepayment.Amount;
                            // _totalAmount = nos Monthls * amount
                            break;
                        }
                        actualTotalRepayment += _totalRepayment;
                    }
                }
                //*****AddExpenses
                var newExpense = new PropertyExpense();
                newExpense = PropertyOwnerService.AddOnboardExpense(login, model.Expenses, newProp.Id);
                //******AddFinancial
                var newFinancial = new PropertyFinance();
                newFinancial = PropertyOwnerService.AddOnboardFinance(login, model, newProp.Id, actualTotalRepayment);
                var ownerPerson = AccountService.GetPersonByLoginId(login.Id);
                if (!model.IsOwnerOccupied)
                {
                    var ten = AccountService.GetExistingLogin(model.TenantToPropertyModel.TenantEmail);
                    if (ten == null)
                    {
                        var sendEmail = false;
                        var temPass   = UtilService.GeneraterRandomKey(8);
                        var createRes = AccountService.CreateTenantAccount(model.TenantToPropertyModel, login, temPass);

                        if (createRes.IsSuccess)
                        {
                            ten       = createRes.NewObject as Login;
                            sendEmail = true;
                        }

                        if (sendEmail)
                        {
                            var emailRes = await EmailService.SendCreateAccountToTenant(model, temPass, ownerPerson);
                        }
                        else
                        {
                            return(Json(new { Success = false, NewPropId = newProp.Id }));
                        }
                        //return Json(new { Success = false, NewPropId = newProp.Id, Todo = "Send email", ErrorMsg = "Cannot find person in login table!" });
                    }
                    else // ten not null
                    {
                        if (!ten.IsActive)
                        {
                            var resultTenantActive = PropertyService.ActivateTenant(login, ten.Id);
                            if (resultTenantActive.IsSuccess)
                            {
                                await EmailService.SendActivationEmailToTenant(model, ownerPerson);
                            }
                        }
                    }
                    var person = AccountService.GetPersonByLoginId(ten.Id);
                    //var result = PropertyService.AddTenantToProperty(login, person.Id, newProp.Id, model.TenantToPropertyModel.StartDate,
                    //    model.TenantToPropertyModel.EndDate, model.TenantToPropertyModel.PaymentFrequencyId, model.TenantToPropertyModel.PaymentAmount);
                    model.TenantToPropertyModel.Liabilities = model.LiabilityValues;
                    model.TenantToPropertyModel.PropertyId  = newProp.Id;
                    var result = PropertyService.AddTenant(login, ten.Id, model.TenantToPropertyModel);
                    if (result.IsSuccess)
                    {
                        return(Json(new { Sucess = true, Msg = "Added!", NewPropId = newProp.Id, result = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                    }
                    else
                    {
                        return(Json(new { Sucess = false, NewPropId = newProp.Id, Msg = result.ErrorMessage, redirect = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                    }
                }
            }
            return(Json(new { Success = status, NewPropId = newProp.Id, message = message, data = tenant }));
        }
Exemple #8
0
        public async Task <ActionResult> AddProperty(PropertyMyOnboardModel model)
        {
            var status  = true;
            var message = "Record added successfully";
            var data    = model;
            AddTenantToPropertyModel tenant = new AddTenantToPropertyModel();

            //*********** AddNewProperty
            var user        = User.Identity.Name;
            var login       = AccountService.GetLoginByEmail(user);
            var newProp     = PropertyOwnerService.AddOnboardProperty(login, model);
            var address     = model.Address.ToAddressString();
            var ownerPerson = AccountService.GetPersonByLoginId(login.Id);
            ////*********** AddRepayments

            var newRepayment = new PropertyRepayment();

            if (newProp == null)
            {
                return(Json(new { Success = false, message = "Cannot find the property!" }));
            }
            else
            {
                newRepayment = PropertyOwnerService.AddOnboardRepayment(login, model.Repayments, newProp.Id);
                decimal _totalRepayment = 0;

                int _nosWeeks      = 0;
                int _nosFortnights = 0;
                int _nosMonthly    = 0;
                if (newRepayment != null)
                {
                    foreach (Service.Models.RepaymentViewModel repayment in model.Repayments)
                    {
                        switch (repayment.FrequencyType)
                        {
                        case 1:     // Weekly
                                    // find the nos of weeks in datediff(StartDate, EndDate)
                            _nosWeeks = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 7;
                            // _totalAmount = nos weeks * amount
                            _totalRepayment = _nosWeeks * newRepayment.Amount;
                            break;

                        case 2:       // Fortnightly
                                      // find the nos of Fortnights in datediff(StartDate, EndDate)
                            _nosFortnights = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 14;
                            // _totalAmount = nos weeks * amount
                            _totalRepayment = _nosFortnights * newRepayment.Amount;
                            break;

                        case 3:     //Monthly
                                    // find the nos of Monthls in datediff(StartDate, EndDate)
                            _nosMonthly     = ((newRepayment.EndDate - newRepayment.StartDate) ?? TimeSpan.Zero).Days / 30;
                            _totalRepayment = _nosMonthly * newRepayment.Amount;
                            // _totalAmount = nos Monthls * amount
                            break;
                        }

                        actualTotalRepayment += _totalRepayment;
                    }
                }

                ////*****AddExpenses
                //var newExpense = new PropertyExpense();
                //newExpense = PropertyOwnerService.AddOnboardExpense(login, model.Expenses, newProp.Id);
                //******AddFinancial
                var newFinancial = new PropertyFinance();
                newFinancial = PropertyOwnerService.AddOnboardFinance(login, model, newProp.Id, actualTotalRepayment);

                //return Json( new { Success = true , PropertyId = newProp.Id});
                if (!model.IsOwnerOccupied)
                {
                    var ten = AccountService.GetExistingLogin(model.TenantToPropertyModel.TenantEmail);
                    if (ten == null)
                    {
                        var    sendEmail = false;
                        string temPass   = null;
                        /// CREATE AN ACCOUNT AND SEND EMAIL TO TENANT TO ACTIVATE AND RESET ACCOUNT
                        temPass = UtilService.GeneraterRandomKey(8);
                        var createRes = AccountService.CreateTenantAccount(model.TenantToPropertyModel, login, temPass);
                        if (createRes.IsSuccess)
                        {
                            ten       = createRes.NewObject as Login;
                            sendEmail = true;
                        }
                        if (sendEmail && temPass != null)
                        {
                            var per = AccountService.GetPersonByLoginId(ten.Id);
                            await EmailService.SendCreateAccountToTenantSendgrid(per, model.TenantToPropertyModel.TenantEmail, temPass, ownerPerson, ten.EmailConfirmationToken, address);
                        }
                    }
                    else
                    {
                        if (!ten.IsActive)
                        {
                            var resultTenantActive = PropertyService.ActivateTenant(login, ten.Id);
                            if (resultTenantActive.IsSuccess)
                            {
                                // SEND EMAIL INTIMATING THAT ACCOUNT HAS BEEN ACTIVATED BY THE OWNER
                                //await SendActivationEmailToTenant(model);
                            }
                            else
                            {
                                return(Json(new { Sucess = false, redirect = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                            }
                        }
                    }
                    var person = AccountService.GetPersonByLoginId(ten.Id);
                    var result = PropertyService.AddTenantToProperty(login, person.Id, newProp.Id, model.TenantToPropertyModel.StartDate,
                                                                     model.TenantToPropertyModel.EndDate, model.TenantToPropertyModel.PaymentFrequencyId, model.TenantToPropertyModel.PaymentAmount);
                    if (result.IsSuccess)
                    {
                        string             url  = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Tenant/Home/MyRentals");
                        SendGridEmailModel mail = new SendGridEmailModel
                        {
                            RecipentName  = model.TenantToPropertyModel.FirstName,
                            ButtonText    = "",
                            ButtonUrl     = url,
                            RecipentEmail = model.TenantToPropertyModel.TenantEmail,
                            OwnerName     = ownerPerson.FirstName,
                            Address       = address,
                        };
                        await EmailService.SendEmailWithSendGrid(EmailType.OwnerAddTenantEmail, mail);

                        return(Json(new { Sucess = true, Msg = "Added!", result = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                    }
                    else
                    {
                        return(Json(new { Sucess = false, Msg = result.ErrorMessage, redirect = "Redirect", url = Url.Action("Index", "PropertyOwners") }));
                    }
                }
            }

            return(Json(new { success = status, message = message, data = tenant }));
        }