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() })); } }
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 async Task <ActionResult> AddRentalApplication(RentalApplicationModel model) { if (ModelState.IsValid) { var files = Request.Files; var userName = User.Identity.Name; if (String.IsNullOrEmpty(userName)) { return(Json(new { Success = false, ErrorMsg = "User not exist!" })); } var login = AccountService.GetLoginByEmail(userName); var result = RentalService.AddRentallApllication(model, login, Request.Files); if (result.IsSuccess) { var propertyOwner = RentalService.GetOwnerDetails(model); var propertyOwnerLogin = AccountService.GetLoginById(propertyOwner.Id); var property = db.Property.FirstOrDefault(x => x.Id == model.PropertyId); var addressString = ""; if (property != null) { var address = PropertyService.GetAddressById(property.AddressId); if (address != null) { if (address.Street != "" && address.City != "") { addressString = address.Number + " " + address.Street + ", " + address.Suburb + ", " + address.City + ", " + address.PostCode; } } } // string url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "PropertyOwners/Property/RentalProperties"); var nvc = new NameValueCollection(); nvc.Add("PropId", model.PropertyId.ToString()); nvc.Add("returnUrl", "/PropertyOwners/Property/RentalProperties"); string url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/PropertyOwners/Property/AllRentalApplications", UtilService.ToQueryString(nvc)); SendGridEmailModel mail = new SendGridEmailModel { RecipentName = propertyOwner.FirstName, ButtonText = "", ButtonUrl = url, RecipentEmail = propertyOwnerLogin.Email, Address = addressString, }; await EmailService.SendEmailWithSendGrid(EmailType.NewApplicationEmail, mail); } return(result.IsSuccess ? Json(new { Success = true }) : Json(new { Success = false, ErrorMsg = result.ErrorMessage })); } return(Json(new { Success = false })); }
// [ValidateAntiForgeryToken] public async Task <JsonResult> ApplicationAccepted(AcceptAndDeclineRentalApplicationModel model) { if (!ModelState.IsValid) { return(Json(new { Success = false })); } var user = User.Identity.Name; var login = AccountService.GetLoginByEmail(user); var result = PropertyService.AcceptApplication(model, login); // send email here if (result.IsSuccess) { var tenantPersonDetails = AccountService.GetPersonById(model.TenantId); var tenatLoginDetails = AccountService.GetLoginById(model.TenantId); var property = db.Property.FirstOrDefault(x => x.Id == model.PropertyId); var addressString = ""; if (property != null) { var address = PropertyService.GetAddressById(property.AddressId); if (address != null) { if (address.Street != "" && address.City != "") { addressString = address.Number + " " + address.Street + ", " + address.Suburb + ", " + address.City + ", " + address.PostCode; } } } string url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "Tenants/Home/MyRentals"); SendGridEmailModel mail = new SendGridEmailModel { RecipentName = tenantPersonDetails.FirstName, ButtonText = "", ButtonUrl = url, RecipentEmail = tenatLoginDetails.Email, Address = addressString, }; await EmailService.SendEmailWithSendGrid(EmailType.AcceptRentalApplication, mail); return(Json(new { Success = result.IsSuccess })); } return(Json(new { Success = result.IsSuccess, Msg = result.ErrorMessage })); }
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() })); } }
public async System.Threading.Tasks.Task <JsonResult> SaveJobQuote(QuoteModel jobQuoteViewModel) { if (ModelState.IsValid) { var files = Request.Files; var user = User.Identity.Name; var login = AccountService.GetLoginByEmail(user); var result = JobService.AddJobQuote(jobQuoteViewModel, login, Request.Files); #region if (result.IsSuccess) { var propertyOwner = JobService.GetOwnerDetails(jobQuoteViewModel.JobRequestId); var propertyOwnerLogin = AccountService.GetLoginById(propertyOwner.Id); var property = db.TenantJobRequest.Where(x => x.Id == jobQuoteViewModel.JobRequestId).Select(x => x.Property).FirstOrDefault(); var nvc = new NameValueCollection(); nvc.Add("marketJobId", jobQuoteViewModel.JobRequestId.ToString()); string url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Jobs/Home/GetJobQuotes", UtilService.ToQueryString(nvc)); SendGridEmailModel mail = new SendGridEmailModel { RecipentName = propertyOwner.FirstName, ButtonText = "", ButtonUrl = url, Address = property.Address.ToAddressString(), RecipentEmail = propertyOwnerLogin.Email, JobTitle = jobQuoteViewModel.Title ?? "No Title", }; await EmailService.SendEmailWithSendGrid(EmailType.NewQuoteEmail, mail); } #endregion return(Json(new { Success = result.IsSuccess, ErrorMsg = result.ErrorMessage ?? "" })); } return(Json(new { success = false })); }
public async Task <ActionResult> AccceptQuote(JobAcceptedModel jobModel) { var user = User.Identity.Name; if (String.IsNullOrEmpty(user)) { return(Json(new { Success = false, Msg = "User not found!" })); } var login = AccountService.GetLoginByEmail(user); var result = JobService.AcceptQuote(jobModel, login); if (result.IsSuccess) { var serviceProviderPersonDetails = JobService.GetPersonByJobQuoteId(jobModel); var serviceProviderLoginDetails = AccountService.GetLoginById(serviceProviderPersonDetails.Id); var jobDetails = JobService.GetMarketJobById(jobModel.JobRequestId); var nvc = new NameValueCollection(); nvc.Add("userAction", "2"); string url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Jobs/Home", UtilService.ToQueryString(nvc)); SendGridEmailModel mail = new SendGridEmailModel { RecipentName = serviceProviderPersonDetails.FirstName, ButtonText = "", ButtonUrl = url, RecipentEmail = serviceProviderLoginDetails.Email, JobTitle = jobDetails.Title ?? "No Title", }; await EmailService.SendEmailWithSendGrid(EmailType.AcceptQuote, mail); return(Json(new { Success = result.IsSuccess, Msg = result.ErrorMessage })); } return(Json(new { Success = false })); }
public async Task <ActionResult> Delete(int id) { var user = User.Identity.Name; var property = db.Property.First(p => p.Id == id); if (property == null) { return(Json(new { Success = false, message = "The selected property can't be found in the database." })); } else { property.IsActive = false; var op = db.OwnerProperty.FirstOrDefault(x => x.PropertyId == id); db.OwnerProperty.Remove(op); var applicants = property.RentalListing.Where(x => x.IsActive).SelectMany(x => x.RentalApplication) .Where(x => x.IsActive && x.ApplicationStatusId != 3) .Select(x => x.Person).Select(x => new Recipient { Name = x.FirstName, Email = x.Login.UserName }).ToList(); var nvc = new NameValueCollection(); var url1 = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Tenants/Home/MyRentalApplications", UtilService.ToQueryString(nvc)); var tenants = property.TenantProperty.Where(x => x.IsActive ?? false) .Select(x => x.Tenant.Person) .Select(x => new Recipient { Name = x.FirstName, Email = x.Login.UserName }).ToList(); var url2 = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Tenants/Home/MyRentals", UtilService.ToQueryString(nvc)); var serviceSuppliers = property.Job.Where(x => x.JobStatusId != 5 || x.JobStatusId != 6 && x.ProviderId != null) .Select(x => x.ServiceProvider.Person) .Select(x => new Recipient { Name = x.FirstName, Email = x.Login.UserName }); var url3 = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, "/Companies/Home/MyJobs", UtilService.ToQueryString(nvc)); foreach (var item in property.RentalListing) { item.IsActive = false; foreach (var app in item.RentalApplication) { app.ApplicationStatusId = 3; } } foreach (var item in property.TenantProperty) { item.IsActive = (item.IsActive ?? false) ? false : item.IsActive; } foreach (var item in property.Job) { item.JobStatusId = (item.JobStatusId != 5 && item.JobStatusId != 6) ? item.JobStatusId = 5 : item.JobStatusId; } var address = property.Address.ToAddressString(); await EmailService.SendEmailToGroup(EmailType.DeletePropertyRentApplicationDeclined, applicants, url1, address); await EmailService.SendEmailToGroup(EmailType.DeletePropertyRentalCanceled, tenants, url2, address); await EmailService.SendEmailToGroup(EmailType.DeletePropertyJobCanceled, serviceSuppliers, url3, address); db.SaveChanges(); return(Json(new { Success = true, message = "Property deleted successfully", id = id })); } }
public async Task <JsonResult> SubmitPropertyRequest(RequestModel model) { if (ModelState.IsValid) { var files = Request.Files;//.MediaFiles;// Request.Files; var userName = User.Identity.Name; if (String.IsNullOrEmpty(userName)) { return(Json(new { Success = false, ErrorMsg = "User not exixt!" })); } var login = AccountService.GetLoginByEmail(userName); var result = PropertyService.AddPropertyRequest(login, model, Request.Files); // If request is sent sucessfully send an email if (result.IsSuccess) { var nvc = new NameValueCollection(); var property = db.Property.First(p => p.Id == model.PropertyId); var address = property.Address.ToAddressString(); // Check if Owner or Tenant is sending request and add url button to redirect in email var btnUrl = model.ToOwner ? "/PropertyOwner/Property/TenantRequests" : "/Tenants/Home/LandLordRequests"; var url = UtilService.UrlGenerator(System.Web.HttpContext.Current.Request, btnUrl, UtilService.ToQueryString(nvc)); List <Recipient> recipient = null; //Select Owners or Teannts depending on who sent Request. // if email is been sent to owner if (model.ToOwner) { recipient = property.OwnerProperty .Select(x => x.Person) .Select(x => new Recipient { Name = x.FirstName, Email = x.Login.UserName, PersonType = "Tenant" }).ToList(); } else { //if email is been sent to all the Tenants if (model.RecipientId == 0) { recipient = property.OwnerProperty .Select(x => x.Person) .Select(x => new Recipient { Name = x.FirstName, Email = x.Login.UserName, PersonType = "Tenant" }).ToList(); } else { // if email is been sent to specific Tenant recipient = new List <Recipient>(); recipient.Add(new Recipient { Name = db.Person.First(x => x.Id == model.RecipientId).FirstName, Email = db.Login.First(y => y.Id == model.RecipientId).UserName, PersonType = "Owner" }); } } await EmailService.SendEmailToGroup(EmailType.NewRequestEmail, recipient, url, address); } return(result.IsSuccess ? Json(new { Success = true }) : Json(new { Success = false, ErrorMsg = result.ErrorMessage })); } else { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(Json(new { Success = false, Model = allErrors })); } }
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 })); }