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 }));
        }
Пример #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 />"
                + "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() }));
            }
        }
Пример #3
0
        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 }));
        }
Пример #4
0
        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
                }));
            }
        }
Пример #5
0
        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 }));
            }
        }
Пример #6
0
        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 }));
        }
Пример #7
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() }));
            }
        }