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 })); }