Example #1
0
 public static ServiceResponseResult AddRentalListing(RentListingModel model, HttpFileCollectionBase files, Login user)
 {
     using (var db = new KeysEntities())
     {
         var foundProp = db.OwnerProperty.FirstOrDefault(x => x.PropertyId == model.PropertyId && x.OwnerId == user.Id);
         if (foundProp == null)
         {
             return(new ServiceResponseResult {
                 IsSuccess = false, ErrorMessage = "Can not find property."
             });
         }
         var newRentalListing = new RentalListing
         {
             PropertyId     = model.PropertyId,
             Description    = model.Description,
             Title          = model.Title = model.Title,
             MovingCost     = model.MovingCost,
             TargetRent     = model.TargetRent,
             AvailableDate  = model.AvailableDate,
             Furnishing     = model.Furnishing,
             IdealTenant    = model.IdealTenant,
             OccupantCount  = model.OccupantCount,
             PetsAllowed    = model.PetsAllowed,
             CreatedBy      = user.Email,
             CreatedOn      = DateTime.UtcNow,
             UpdatedBy      = user.Email,
             IsActive       = true,
             RentalStatusId = 1
         };
         var fileList = MediaService.SaveMediaFiles(files, 5, null).NewObject as List <MediaModel>;
         if (fileList != null)
         {
             fileList.ForEach(x => newRentalListing.RentalListingMedia.Add(new RentalListingMedia {
                 NewFileName = x.NewFileName, OldFileName = x.OldFileName
             }));
         }
         db.RentalListing.Add(newRentalListing);
         try
         {
             db.SaveChanges();
             return(new ServiceResponseResult {
                 IsSuccess = true
             });
         }
         catch (Exception ex)
         {
             return(new ServiceResponseResult {
                 IsSuccess = true, ErrorMessage = _error
             });
         }
     }
 }
Example #2
0
        public static ServiceResponseResult AddJobQuote(QuoteModel model, Login login, HttpFileCollectionBase files = null)
        {
            using (var db = new KeysEntities())
            {
                var _currentJobId        = model.JobRequestId;
                var _currentJobMaxBudget = db.TenantJobRequest.SingleOrDefault(j => j.Id == _currentJobId).MaxBudget;
                if (_currentJobMaxBudget != null && _currentJobMaxBudget < model.Amount)
                {
                    return(new ServiceResponseResult
                    {
                        IsSuccess = false,
                        ErrorMessage = "Sorry, you quote is larger than Max Budget of this Job."
                    });
                }
                if (model.Id == -1)
                {
                    var jobQuote = new JobQuote();
                    var mf       = MediaService.SaveMediaFiles(files, 5);
                    if (mf.IsSuccess)
                    {
                        var mediaFiles = mf.NewObject as List <MediaModel>;
                        if (mediaFiles != null)
                        {
                            mediaFiles.ForEach(x => jobQuote.JobQuoteMedia.Add(new JobQuoteMedia
                            {
                                FileName = x.NewFileName,
                                IsActive = true
                            }));
                        }
                    }
                    // Bug Fix #2031
                    jobQuote.JobRequestId = model.JobRequestId;
                    jobQuote.ProviderId   = login.Id;
                    jobQuote.Status       = "opening".ToLower();
                    jobQuote.Amount       = model.Amount;
                    jobQuote.CreatedBy    = login.Email;
                    jobQuote.UpdatedBy    = login.Email;
                    jobQuote.CreatedOn    = DateTime.UtcNow;
                    jobQuote.UpdatedOn    = DateTime.UtcNow;
                    jobQuote.Note         = model.Note;
                    jobQuote.IsViewed     = false;
                    db.JobQuote.Add(jobQuote);
                }
                else
                {
                    var jobQuote  = db.JobQuote.Find(model.Id);
                    var marketJob = db.TenantJobRequest.Find(model.JobRequestId);

                    if (jobQuote != null && marketJob != null)
                    {
                        jobQuote.Amount    = model.Amount;
                        jobQuote.UpdatedBy = login.Email;
                        jobQuote.UpdatedOn = DateTime.UtcNow;
                    }
                }
                try
                {
                    db.SaveChanges();
                    return(new ServiceResponseResult {
                        IsSuccess = true
                    });
                }
                catch (Exception)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
            }
        }
Example #3
0
        public static ServiceResponseResult <List <MediaModel> > EditRentalListing(RentListingModel model, HttpFileCollectionBase files, Login user)
        {
            using (var db = new KeysEntities())
            {
                var foundProp = db.OwnerProperty.FirstOrDefault(x => x.PropertyId == model.PropertyId && x.OwnerId == user.Id);
                if (foundProp == null)
                {
                    return(new ServiceResponseResult <List <MediaModel> > {
                        IsSuccess = false, ErrorMessage = "Can not find property."
                    });
                }
                var oldRentalListing = db.RentalListing.Find(model.Id);
                oldRentalListing.Description   = model.Description;
                oldRentalListing.Title         = model.Title;
                oldRentalListing.MovingCost    = model.MovingCost;
                oldRentalListing.TargetRent    = model.TargetRent;
                oldRentalListing.AvailableDate = model.AvailableDate;
                oldRentalListing.Furnishing    = model.Furnishing;
                oldRentalListing.IdealTenant   = model.IdealTenant;
                oldRentalListing.OccupantCount = model.OccupantCount;
                oldRentalListing.PetsAllowed   = model.PetsAllowed;
                oldRentalListing.UpdatedBy     = user.Email;
                oldRentalListing.UpdatedOn     = DateTime.UtcNow;
                if (model.FilesRemoved != null)
                {
                    model.FilesRemoved.ToList().ForEach(x =>
                    {
                        var media = oldRentalListing.RentalListingMedia.FirstOrDefault(y => y.Id == x);
                        if (media != null)
                        {
                            db.RentalListingMedia.Remove(media);
                            MediaService.RemoveMediaFile(media.NewFileName);
                        }
                    });
                }


                var fileList = MediaService.SaveMediaFiles(files, 5, null).NewObject as List <MediaModel>;
                if (fileList != null)
                {
                    fileList.ForEach(x => oldRentalListing.RentalListingMedia.Add(new RentalListingMedia {
                        NewFileName = x.NewFileName, OldFileName = x.OldFileName
                    }));
                }

                try
                {
                    db.SaveChanges();
                    var medias = oldRentalListing.RentalListingMedia
                                 .Select(x => MediaService.GenerateViewProperties(new MediaModel {
                        Id = x.Id, NewFileName = x.NewFileName, OldFileName = x.OldFileName
                    })).ToList();
                    return(new ServiceResponseResult <List <MediaModel> > {
                        IsSuccess = true, Result = medias
                    });
                }
                catch (Exception ex)
                {
                    return(new ServiceResponseResult <List <MediaModel> > {
                        IsSuccess = true, ErrorMessage = _error
                    });
                }
            }
        }
Example #4
0
        public static ServiceResponseResult AddNewCompany(CompanyViewModel model, Login login, HttpFileCollectionBase files)
        {
            using (var db = new KeysEntities())
            {
                var foundSp = db.ServiceProvider.FirstOrDefault(x => x.Id == login.Id);
                if (foundSp == null)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = "Can not find account!"
                    });
                }
                var physicalAddress = new Address
                {
                    CountryId = 1,
                    CreatedBy = login.Email,
                    CreatedOn = DateTime.Now,
                    UpdatedBy = login.Email,
                    UpdatedOn = DateTime.Now,
                    Number    = model.PhysicalAddress.Number,
                    Street    = model.PhysicalAddress.Street,
                    City      = model.PhysicalAddress.City,
                    Suburb    = model.PhysicalAddress.Suburb,
                    PostCode  = model.PhysicalAddress.PostCode,
                    Lat       = model.PhysicalAddress.Latitude,
                    Lng       = model.PhysicalAddress.Longitude,
                    IsActive  = true
                };
                try
                {
                    db.Address.Add(physicalAddress);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
                var serviceProvider = new Company
                {
                    IsActive          = true,
                    Name              = model.Name,
                    Website           = model.Website,
                    PhoneNumber       = model.PhoneNumber,
                    UpdatedBy         = login.Email,
                    CreatedOn         = DateTime.Now,
                    CreatedBy         = login.Email,
                    UpdatedOn         = DateTime.Now,
                    PhysicalAddressId = physicalAddress.AddressId,
                };
                if (model.IsShipSame)
                {
                    serviceProvider.BillingAddressId = physicalAddress.AddressId;
                }
                else
                {
                    var billingAddress = new Address
                    {
                        CountryId = 1,
                        CreatedBy = login.Email,
                        CreatedOn = DateTime.Now,
                        UpdatedBy = login.Email,
                        UpdatedOn = DateTime.Now,
                        Number    = model.BillingAddress.Number,
                        Street    = model.BillingAddress.Street,
                        City      = model.BillingAddress.City,
                        Suburb    = model.BillingAddress.Suburb,
                        PostCode  = model.BillingAddress.PostCode,
                        Lat       = model.PhysicalAddress.Latitude,
                        Lng       = model.PhysicalAddress.Longitude,
                        IsActive  = true
                    };
                    try
                    {
                        db.Address.Add(billingAddress);
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        return(new ServiceResponseResult {
                            IsSuccess = false, ErrorMessage = _error
                        });
                    }
                    serviceProvider.BillingAddressId = billingAddress.AddressId;
                }
                var saveResult = MediaService.SaveMediaFiles(files, 1);
                if (saveResult.IsSuccess)
                {
                    var newOb = saveResult.NewObject as List <MediaModel>;
                    serviceProvider.ProfilePhoto = newOb.FirstOrDefault().NewFileName;
                }

                foundSp.Company = serviceProvider;
                try
                {
                    db.Company.Add(serviceProvider);
                    foundSp.Company           = serviceProvider;
                    foundSp.IsProfileComplete = true;
                    db.SaveChanges();
                    return(new ServiceResponseResult {
                        IsSuccess = true
                    });
                }
                catch (Exception ex)
                {
                    return(new ServiceResponseResult {
                        IsSuccess = false, ErrorMessage = _error
                    });
                }
            }
        }