示例#1
0
        public async Task <ActionResult> SendActivationEmailToTenant(PropertyMyOnboardModel 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 nvc         = new NameValueCollection();

            nvc.Set("TenantEmail", model.TenantToPropertyModel.TenantEmail);
            string url     = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Account/RegisterToBeTenant", 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 EmailService.SendAsync(msg);

                return(Json(new { Success = true, Status = "Await response" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = false, msg = ex.ToString() }));
            }
        }
示例#2
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
                });
            }
        }
示例#3
0
        public static PropertyFinance AddOnboardFinance(Login user, PropertyMyOnboardModel model, int PropertyId, decimal TotalRepayment)
        {
            using (var db = new KeysEntities())
            {
                try
                {
                    var newFinancial  = new PropertyFinance();
                    var newHomeValues = new PropertyHomeValue();
                    var totalExpense  = db.PropertyExpense.Where(t => t.PropertyId == PropertyId).Select(t => t.Amount).DefaultIfEmpty().Sum();

                    newFinancial.CurrentHomeValue = model.CurrentHomeValue;
                    newFinancial.PurchasePrice    = model.PurchasePrice;
                    newFinancial.Mortgage         = model.Mortgage;
                    newFinancial.PropertyId       = PropertyId;
                    newFinancial.PurchasePrice    = model.PurchasePrice;
                    newFinancial.TotalRepayment   = TotalRepayment;
                    newFinancial.TotalExpense     = totalExpense;
                    db.PropertyFinance.Add(newFinancial);

                    // Add the homeValue to db.PropertyHomeValue with the property id into propertyHomeValue
                    newHomeValues.PropertyId      = PropertyId;
                    newHomeValues.Value           = model.CurrentHomeValue ?? 0;
                    newHomeValues.Date            = DateTime.Today;
                    newHomeValues.HomeValueTypeId = model.HomeValueType;
                    newHomeValues.CreatedBy       = user.UserName;
                    newHomeValues.CreatedOn       = DateTime.Today;
                    newHomeValues.IsActive        = true;
                    db.PropertyHomeValue.Add(newHomeValues);
                    db.SaveChanges();
                    return(newFinancial);
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
        }
示例#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
                });
            }
        }
示例#5
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 }));
        }
示例#6
0
        //****mchanged the viewmodel from PropertyOnboardModel to PropertyMyOnboardModel
        public static Property AddOnboardProperty(Login user, PropertyMyOnboardModel model)
        {
            using (var db = new KeysEntities())
            {
                var adModel = model.Address;
                var address = new Address
                {
                    Number    = adModel.Number,
                    Street    = adModel.Street,
                    City      = adModel.City,
                    Suburb    = adModel.Suburb ?? adModel.City,
                    PostCode  = adModel.PostCode,
                    CountryId = 1,
                    CreatedOn = DateTime.UtcNow,
                    IsActive  = true,
                    CreatedBy = user.Email,
                    UpdatedBy = user.Email,
                    UpdatedOn = DateTime.UtcNow,
                    Lat       = adModel.Latitude,
                    Lng       = adModel.Longitude,
                    Region    = adModel.Region
                };
                db.Address.Add(address);
                db.SaveChanges();
                var newProperty = new Property
                {
                    AddressId        = address.AddressId,
                    Name             = model.PropertyName,
                    IsActive         = true,
                    Bathroom         = model.Bathroom,
                    Bedroom          = model.Bedroom,
                    CreatedBy        = user.Email,
                    CreatedOn        = DateTime.UtcNow,
                    UpdatedBy        = user.Email,
                    UpdatedOn        = DateTime.UtcNow,
                    Description      = model.Description,
                    FloorArea        = model.FloorArea,
                    LandSqm          = model.LandArea,
                    ParkingSpace     = model.ParkingSpace,
                    YearBuilt        = model.YearBuilt,
                    PropertyTypeId   = model.PropertyTypeId,
                    TargetRent       = model.TenantToPropertyModel?.PaymentAmount ?? 0,
                    TargetRentTypeId = model.TargetRentType,
                    IsOwnerOccupied  = model.IsOwnerOccupied
                };
                db.Property.Add(newProperty);
                var checkOwner = db.Owners.Where(x => x.Id == user.Id).FirstOrDefault();
                if (checkOwner == null)
                {
                    var newOwner = new Owners
                    {
                        Id = user.Id
                    };
                    db.Owners.Add(newOwner);
                }

                db.SaveChanges();
                var person = AccountService.GetPersonByLoginId(user.Id);

                var ownerProperty = new OwnerProperty
                {
                    PropertyId        = newProperty.Id,
                    OwnershipStatusId = 1,
                    OwnerId           = user.Id,
                    CreatedBy         = user.Email,
                    UpdatedBy         = user.Email,
                    PurchaseDate      = DateTime.UtcNow, // Should Create a feild in the Add property page and get value from there
                    UpdatedOn         = DateTime.UtcNow,
                    CreatedOn         = DateTime.UtcNow
                };
                db.OwnerProperty.Add(ownerProperty);
                db.SaveChanges();
                return(newProperty);
            }
        }
示例#7
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 }));
        }