コード例 #1
0
 public static Person GetOwnerDetails(RentalApplicationModel model)
 {
     using (var db = new KeysEntities())
     {
         var ownerId = db.RentalListing.Where(x => x.Id == model.RentalListingId).Select(y => y.Property.OwnerProperty.FirstOrDefault().Person.Id).FirstOrDefault();
         return(db.Person.FirstOrDefault(x => x.Id == ownerId));
     }
 }
コード例 #2
0
        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 }));
        }
コード例 #3
0
        public 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 exixt!" }));
                }
                var login = AccountService.GetLoginByEmail(userName);
            }
            return(Json(new { Success = false }));
        }
コード例 #4
0
ファイル: RentalService.cs プロジェクト: lane-dev/key-core
 public static ServiceResponseResult AddRentallApllication(RentalApplicationModel model, Login login, HttpFileCollectionBase files = null)
 {
     using (var db = new KeysEntities())
     {
         var result = new ServiceResponseResult {
             IsSuccess = false
         };
         if (!TenantService.IsLoginATenant(login))
         {
             var errorMsg = "Account not tenant!";
             result.ErrorMessage = errorMsg;
             return(result);
         }
         var rentalApp = new RentalApplication
         {
             RentalListingId     = model.RentalListingId,
             PersonId            = login.Id,
             TenantsCount        = model.TenantsCount,
             ApplicationStatusId = 1,
             Note      = model.Note,
             CreatedBy = login.Email,
             CreatedOn = DateTime.UtcNow,
             UpdatedBy = login.Email,
             UpdatedOn = DateTime.UtcNow,
             IsActive  = true,
         };
         var mediaFiles = MediaService.SaveFiles(files, 5, AllowedFileType.AllFiles).NewObject as List <MediaModel>;
         mediaFiles.ForEach(x => rentalApp.RentalApplicationMedia.Add(new RentalApplicationMedia
         {
             NewFileName = x.NewFileName,
             OldFileName = x.OldFileName,
         }));
         try
         {
             db.RentalApplication.Add(rentalApp);
             db.SaveChanges();
             return(new ServiceResponseResult {
                 IsSuccess = true
             });
         }
         catch (Exception ex)
         {
             return(new ServiceResponseResult {
                 IsSuccess = false, ErrorMessage = _error
             });
         }
     }
 }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: lane-dev/key-core
 public JsonResult EditTenancyApplication(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 exixt!" }));
         }
         var login  = AccountService.GetLoginByEmail(userName);
         var result = RentalService.EditRentallApllication(model, login, Request.Files);
         return(result.IsSuccess ? Json(new { Success = true, MediaFiles = result.NewObject as List <MediaModel> }) : Json(new { Success = false, ErrorMsg = result.ErrorMessage }));
     }
     else
     {
         return(Json(new { Success = false }));
     }
 }
コード例 #6
0
 public static ServiceResponseResult AddRentallApllication(RentalApplicationModel model, Login login, HttpFileCollectionBase files = null)
 {
     return(new ServiceResponseResult {
         IsSuccess = true
     });
 }
コード例 #7
0
        public static ServiceResponseResult EditRentallApllication(RentalApplicationModel model, Login login, HttpFileCollectionBase files = null)
        {
            using (var db = new KeysEntities())
            {
                var result = new ServiceResponseResult {
                    IsSuccess = false
                };
                if (!TenantService.IsLoginATenant(login))
                {
                    var errorMsg = "Account not tenant!";
                    result.ErrorMessage = errorMsg;
                    return(result);
                }
                var foundRentalApplication = db.RentalApplication.Where(x => x.Id == model.Id).FirstOrDefault();
                if (foundRentalApplication == null)
                {
                    var errorMsg = "Cannot locate the Rental application";
                    result.ErrorMessage = errorMsg;
                    return(result);
                }
                else
                {
                    foundRentalApplication.RentalListingId     = model.RentalListingId;
                    foundRentalApplication.PersonId            = login.Id;
                    foundRentalApplication.TenantsCount        = model.TenantsCount;
                    foundRentalApplication.Note                = model.Note;
                    foundRentalApplication.ApplicationStatusId = 1;
                    foundRentalApplication.CreatedBy           = login.Email;
                    foundRentalApplication.CreatedOn           = DateTime.UtcNow;
                    foundRentalApplication.UpdatedBy           = login.Email;
                    foundRentalApplication.UpdatedOn           = DateTime.UtcNow;
                    foundRentalApplication.IsActive            = true;

                    model.FilesRemoved.ForEach(x => {
                        var media = db.RentalApplicationMedia.FirstOrDefault(y => y.Id == x);
                        if (media != null)
                        {
                            db.RentalApplicationMedia.Remove(media); MediaService.RemoveMediaFile(media.NewFileName);
                        }
                    });
                    var mediaFiles = MediaService.SaveFiles(files, 5 - foundRentalApplication.RentalApplicationMedia.Count, AllowedFileType.AllFiles).NewObject as List <MediaModel>;
                    if (mediaFiles != null)
                    {
                        mediaFiles.ForEach(x => foundRentalApplication.RentalApplicationMedia.Add(new RentalApplicationMedia
                        {
                            NewFileName = x.NewFileName,
                            OldFileName = x.OldFileName,
                        }));
                    }
                };
                try
                {
                    db.SaveChanges();
                    var mFiles = new List <MediaModel>();
                    var medias = foundRentalApplication.RentalApplicationMedia
                                 .Select(x => MediaService.GenerateViewProperties(new MediaModel {
                        Id = x.Id, NewFileName = x.NewFileName, OldFileName = x.OldFileName
                    })).ToList();
                    return(new ServiceResponseResult {
                        IsSuccess = true, NewObject = mFiles
                    });
                }
                catch (Exception ex)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
            }
        }