コード例 #1
0
        //*************************************************************************************
        public static PropertyRepayment AddOnboardRepayment(Login user, List <RepaymentViewModel> model, int PropertyId)
        {
            using (var db = new KeysEntities())
            {
                try
                {
                    var newRepayment = new PropertyRepayment();
                    foreach (Service.Models.RepaymentViewModel repayment in model)
                    {
                        newRepayment.PropertyId    = PropertyId;
                        newRepayment.Amount        = repayment.Amount;
                        newRepayment.EndDate       = repayment.EndDate;
                        newRepayment.StartDate     = repayment.StartDate;
                        newRepayment.FrequencyType = repayment.FrequencyType;
                        newRepayment.CreatedBy     = user.UserName;
                        newRepayment.CreatedOn     = DateTime.Today;

                        db.PropertyRepayment.Add(newRepayment);
                        db.SaveChanges();
                    }
                    return(newRepayment);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
コード例 #2
0
 public ActionResult SaveRepayment(RepaymentViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Id > 0)
         {
             var repayment = db.PropertyRepayment.FirstOrDefault(x => x.Id == model.Id);
             if (repayment == null)
             {
                 return(Json(new { Success = false }));
             }
             repayment.Amount        = model.Amount;
             repayment.FrequencyType = model.FrequencyType;
             repayment.StartDate     = model.StartDate;
             repayment.EndDate       = model.EndDate;
             db.SaveChanges();
             return(Json(new { Success = true }));
         }
         else
         {
             var newRepayment = new PropertyRepayment
             {
                 PropertyId    = model.PropertyId,
                 Amount        = model.Amount,
                 FrequencyType = model.FrequencyType,
                 StartDate     = model.StartDate,
                 EndDate       = model.EndDate
             };
             db.PropertyRepayment.Add(newRepayment);
             db.SaveChanges();
             return(Json(new { Success = true, NewId = newRepayment.Id }));
         }
     }
     else
     {
         return(Json(new { Success = false }));
     }
 }
コード例 #3
0
        public JsonResult UpdateFinance(FinancialModel model)
        {
            var     status = true;
            decimal actualTotalRepayment = 0;
            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);

            ////*********** AddRepayments

            var newRepayment = new PropertyRepayment();



            newRepayment = PropertyOwnerService.AddOnboardRepayment(login, model.Repayments, model.PropId);
            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, model.PropId);
                //******AddFinancial
                var newFinancial = new PropertyFinance();
                newFinancial = PropertyOwnerService.AddPropertyFinance(login, model, model.PropId, actualTotalRepayment);

                var newRentalPayment = new PropertyRentalPayment();
                //      newRentalPayment = PropertyOwnerService.AddOnboardRentalPayment(login, model.RentalPayments, model.PropId);
            }

            return(Json(new { success = status, message = message }));
        }
コード例 #4
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 }));
        }
コード例 #5
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 }));
        }