상속: Address
예제 #1
0
        public virtual async Task <Response> Create(PropertyListing model)
        {
            try
            {
                model.AgentId            = User.GetLocalUserId();
                model.CreatedBy          = User.Identity.Name;
                model.CreatedOn          = DateTime.UtcNow;
                model.LastEditedBy       = User.Identity.Name;
                model.LastEditedOn       = DateTime.UtcNow;
                model.Confidential       = false;
                model.Featured           = false;
                model.AskingPrice        = 0;
                model.Fees               = 0;
                model.Rent               = 0;
                model.Premium            = 0;
                model.AskingPriceDisplay = "{0}";
                model.FeesDisplay        = "{0}";
                model.RentDisplay        = "{0}";
                model.PremiumDisplay     = "{0}";
                model.ShareCount         = 0;
                model.Views              = 0;

                List <string> leaseStatuses = _propertySettings.GetLeaseStatuses();
                if (leaseStatuses.Count > 0)
                {
                    model.LeaseStatus = leaseStatuses.FirstOrDefault();
                }
                else
                {
                    model.LeaseStatus = "Available";
                }

                Dictionary <string, string> planningTypes = _propertySettings.GetPlanningTypes();
                if (planningTypes.Count > 0)
                {
                    model.Planning = planningTypes.FirstOrDefault().Key;
                }
                else
                {
                    model.Planning = "VAR";
                }

                List <string> listingTypes = _propertySettings.GetListingTypes();
                if (listingTypes.Count > 0)
                {
                    model.ListingType = listingTypes.FirstOrDefault();
                }
                else
                {
                    model.ListingType = "Not Specified";
                }

                // Geocode
                Geocoding.Google.GoogleAddress address = _address.GeocodeAddress(model);
                if (address != null)
                {
                    model.SetLocation(address.Coordinates);
                }

                await _property.AddAsync(model);

                if (model.Metadata == null)
                {
                    model.Metadata = new List <PropertyMeta>();
                }

                model.UpdateMeta("PlanningDescription", Engine.Settings.Property.GetPlanningTypes().FirstOrDefault().Value);

                for (int i = 0; i < 11; i++)
                {
                    model.AddMeta("Feature" + i.ToString(), "", "System.String");
                }

                await _property.UpdateAsync(model);

                return(new Response(true, "Created successfully."));;
            }
            catch (Exception ex)
            {
                return(await ErrorResponseAsync <BasePropertyController>($"Error creating a new property.", ex));
            }
        }
        private RealEstate CreateRealEstate(CreateRealEstateViewModel realEstate, GoogleAddress addressFull)
        {
            var userId = this.User.Identity.GetUserId();
            var currentlyLoggedUser = this.usersService.GetUserDetailsById(userId);

            realEstate.Country = addressFull.Components[3].LongName;
            realEstate.City = addressFull.Components[1].LongName;

            var dbRealEstate = this.Mapper.Map<RealEstate>(realEstate);
            dbRealEstate.PublisherId = userId;
            if (currentlyLoggedUser.MyOwnAgencyId !=null)
            {
                dbRealEstate.AgencyId = currentlyLoggedUser.MyOwnAgencyId;
            }

            dbRealEstate.Latitude = addressFull.Coordinates.Latitude;
            dbRealEstate.Longitude = addressFull.Coordinates.Longitude;

            var visitors = new VisitorsDetails();
            visitors.AllUsers.Add(currentlyLoggedUser);

            var visitorsDetailsId = this.visitorsService.Add(visitors);
            dbRealEstate.VisitorsDetailsId = visitorsDetailsId;
            dbRealEstate.VisitorsDetails = visitors;
            return dbRealEstate;
        }