public void CouldNotLocate_SSG_RealEstateProperty_should_map_to_RealEstateProperty_correctly()
        {
            SSG_Asset_RealEstateProperty property = new SSG_Asset_RealEstateProperty
            {
                CouldNotLocate = true
            };

            RealEstateProperty p = _mapper.Map <RealEstateProperty>(property);

            Assert.AreEqual(Constants.CouldNotLocate, p.LegalDescription);
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "id,Address,Latitude,Longitude,OriginalSaleAmount,SoldAmount,SaleDate,CategoryId")] RealEstateProperty realEstateProperty)
 {
     if (ModelState.IsValid)
     {
         db.Entry(realEstateProperty).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "name", realEstateProperty.CategoryId);
     return(View(realEstateProperty));
 }
Example #3
0
        public static PropertyViewModel Map(this RealEstateProperty realEstateProperty)
        {
            var result = new PropertyViewModel();

            result.PropertyId          = realEstateProperty.PropertyId;
            result.PropertyName        = realEstateProperty.PropertyName;
            result.PropertyDescription = realEstateProperty.PropertyDescription;
            result.PropertyAddress     = realEstateProperty.PropertyAddress;
            result.PropertyValue       = realEstateProperty.PropertyValue;
            result.OwnedBy             = realEstateProperty.User.UserName;
            return(result);
        }
        public void Create(int size, int?floor, int?maxFloor, string district, string propertyType, string buildingType, int?year,
                           int price)
        {
            if (district == null)
            {
                throw new ArgumentNullException(nameof(district));
            }
            var property = new RealEstateProperty
            {
                Size  = size,
                Price = price,
                Year  = year < 1800 ? null : year,
                Floor = floor <= 0 ? null : floor,
                TotalNumberOfFloors = maxFloor <= 0 ? null : maxFloor,
            };

            //District
            var districtEntity = db.Districts
                                 .FirstOrDefault(x => x.Name.Trim() == district.Trim()) ??
                                 new District()
            {
                Name = district
            };

            property.District = districtEntity;

            //Property Type
            var propertyTypeEntity = db.PropertyTypes
                                     .FirstOrDefault(x => x.Name.Trim() == propertyType.Trim()) ??
                                     new PropertyType()
            {
                Name = propertyType
            };

            property.PropertyType = propertyTypeEntity;

            //Building Type
            var buildingTypeEntity = db.BuildingTypes
                                     .FirstOrDefault(x => x.Name.Trim() == buildingType.Trim()) ??
                                     new BuildingType()
            {
                Name = buildingType
            };

            property.BuildingType = buildingTypeEntity;

            //TODO: Tags

            this.db.RealEstateProperties.Add(property);
            this.db.SaveChanges();

            this.UpdateTags(property.Id);
        }
Example #5
0
        public async Task PropertyService_AddPropertyBulkAsync_Test()
        {
            try
            {
                using (db = new DatabaseContext(dbContextOpt.Options))
                {
                    for (int i = 0; i < 10000; i++)
                    {
                        Guid   PropertyId = Guid.NewGuid();
                        Guid   UserId     = Guid.Parse("10445DB1-C5B0-478A-89F6-613450414ED4");
                        string Name       = $"Trail {i}";
                        string Address    = $"Trail Address {i}";
                        string City       = $"Trail City {i}";
                        string ContactNo  = "9632587410";
                        string Owner      = $"Trail Owner {i}";
                        int    TotalRooms = 0;

                        var propertyModel = new PropertyModel
                        {
                            PropertyId = Guid.NewGuid(),
                            UserId     = UserId,
                            Name       = Name,
                            Address    = Address,
                            City       = City,
                            ContactNo  = ContactNo,
                            Owner      = Owner,
                            TotalRooms = TotalRooms
                        };

                        var property = new RealEstateProperty
                        {
                            Id         = Guid.NewGuid(),
                            UserId     = propertyModel.UserId,
                            Name       = propertyModel.Name,
                            Address    = propertyModel.Address,
                            City       = propertyModel.City,
                            ContactNo  = propertyModel.ContactNo,
                            Owner      = propertyModel.Owner,
                            TotalRooms = propertyModel.TotalRooms
                        };

                        db.RealEstateProperties.Add(property);
                        await db.SaveChangesAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                logService.Log("Add New Property", ex.InnerException.Message, ex.Message, ex.StackTrace);
                Assert.Fail();
            }
        }
Example #6
0
        public static RealEstateProperty Map(this PropertyViewModel propertyViewModel)
        {
            var result = new RealEstateProperty();

            result.PropertyId          = propertyViewModel.PropertyId;
            result.PropertyName        = propertyViewModel.PropertyName;
            result.PropertyDescription = propertyViewModel.PropertyDescription;
            result.PropertyAddress     = propertyViewModel.PropertyAddress;
            result.PropertyValue       = propertyViewModel.PropertyValue;
            result.UserId = propertyViewModel.OwnedBy;

            return(result);
        }
Example #7
0
 private static PropertyViewModel MapToPropertyViewModel(RealEstateProperty x)
 {
     return(new PropertyViewModel
     {
         Price = x.Price,
         Floor = (x.Floor ?? 0).ToString() + "/" + (x.TotalNumberOfFloors ?? 0).ToString(),
         Size = x.Size,
         Year = x.Year,
         BuildingType = x.BuildingType.Name,
         District = x.District.Name,
         PropertyType = x.PropertyType.Name
     });
 }
Example #8
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            if (realEstateProperty == null)
            {
                return(HttpNotFound());
            }
            return(View(realEstateProperty));
        }
Example #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            RealEstateProperty rs = db.RealEstateProperties.Find(id);

            db.RealEstateProperties.Remove(rs);
            db.SaveChanges();
            if (Request.IsAjaxRequest())
            {
                return(Content(""));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #10
0
        // GET: RealEstateProperties/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            if (realEstateProperty == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "name", realEstateProperty.CategoryId);
            return(View(realEstateProperty));
        }
Example #11
0
        public void Create(string district, int size, int?year, int price, string propertyType, string buildingType, int?floor, int?maxFloors)
        {
            RealEstateProperty property = new RealEstateProperty
            {
                Size  = size,
                Price = price,
                Year  = year < 1800 ? null : year,
                Floor = floor <= 0 ? null : floor,
                TotalNumberOfFloors = maxFloors <= 0 ? null : maxFloors
            };

            District districtEntity = this.db.Districts.FirstOrDefault(x => x.Name.Trim() == district.Trim());

            if (districtEntity == null)
            {
                districtEntity = new District {
                    Name = district
                };
            }

            property.District = districtEntity;

            BuildingType buildingTypeEntity = this.db.BuildingTypes.FirstOrDefault(x => x.Name.Trim() == buildingType.Trim());

            if (buildingTypeEntity == null)
            {
                buildingTypeEntity = new BuildingType {
                    Name = buildingType
                };
            }
            property.BuildingType = buildingTypeEntity;

            PropertyType propertyTypeEntity = this.db.PropertyTypes.FirstOrDefault(x => x.Name.Trim() == propertyType.Trim());

            if (propertyTypeEntity == null)
            {
                propertyTypeEntity = new PropertyType {
                    Name = propertyType
                };
            }
            property.PropertyType = propertyTypeEntity;

            this.db.RealEstateProperties.Add(property);
            this.db.SaveChanges();

            this.UpdateTags(property.Id);
        }
        private static JObject GetRealEstate(RealEstateProperty prop, string relationshipName = null, int?relative_index = null)
        {
            JObject jRealEstate = new JObject();

            // "text" - "Полная строка наименования недвижимости, которая была в оригинальном документе (сырое значение)",
            jRealEstate.Add(new JProperty("text", prop.Text));
            jRealEstate.Add(new JProperty("square", prop.square));
            jRealEstate.Add(new JProperty("relative", relationshipName));
            AddNotNullProp(jRealEstate, "relative_index", relative_index);
            jRealEstate.Add(new JProperty("own_type_by_column", prop.own_type_by_column));
            AddNotNullProp(jRealEstate, "square_raw", prop.square_raw);
            AddNotNullProp(jRealEstate, "country_raw", prop.country_raw);
            AddNotNullProp(jRealEstate, "type_raw", prop.type_raw);
            AddNotNullProp(jRealEstate, "own_type_raw", prop.own_type_raw);

            return(jRealEstate);
        }
        public void SSG_RealEstateProperty_should_map_to_RealEstateProperty_correctly()
        {
            SSG_Asset_RealEstateProperty property = new SSG_Asset_RealEstateProperty
            {
                PID          = "pdi",
                TitleNumber  = "title123",
                AddressLine1 = "line1",
                City         = "city"
            };

            RealEstateProperty p = _mapper.Map <RealEstateProperty>(property);

            Assert.AreEqual("pdi", p.Pid);
            Assert.AreEqual("title123", p.TitleNumber);
            Assert.AreEqual("line1", p.PropertyAddress.AddressLine1);
            Assert.AreEqual("city", p.PropertyAddress.City);
        }
Example #14
0
        public ActionResult CustomEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            if (realEstateProperty == null)
            {
                return(HttpNotFound());
            }
            var returnData =
                JsonConvert.SerializeObject(realEstateProperty, Formatting.Indented, new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(returnData));
        }
        public async Task <RealEstateProperty> CreateRealEstateProperty(RealEstateProperty realEstateProperty)
        {
            if (realEstateProperty == null)
            {
                throw new ArgumentNullException(nameof(realEstateProperty));
            }
            var realEstatePropertyData = RealEstateContext.RealEstateProperty.
                                         FirstOrDefault(x => x.PropertyName == realEstateProperty.PropertyName && x.IsActive);

            if (realEstatePropertyData != null)
            {
                throw new InvalidOperationException(Constants.PropertyExistsMessage);
            }

            realEstateProperty.CreatedDate = System.DateTime.Now;
            realEstateProperty.IsActive    = true;
            RealEstateContext.RealEstateProperty.Add(realEstateProperty);
            await RealEstateContext.SaveChangesAsync();

            return(realEstateProperty);
        }
Example #16
0
        public ActionResult CustomSell(int id, String SoldAmount)
        {
            RealEstateProperty realEstatePropertyVal = db.RealEstateProperties.Find(id);

            realEstatePropertyVal.SaleDate   = DateTime.Now;
            realEstatePropertyVal.SoldAmount = ((String.IsNullOrEmpty(SoldAmount) || SoldAmount.Equals("null")) ? (decimal?)null : Convert.ToDecimal(SoldAmount));
            if (ModelState.IsValid)
            {
                db.RealEstateProperties.AddOrUpdate(realEstatePropertyVal);
                db.SaveChanges();
                if (Request.IsAjaxRequest())
                {
                    return(Content(""));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(RedirectToAction("Index"));
        }
        void ParseRealtiesByAntlr(string ownTypeByColumn, string cellText, Person person)
        {
            var parser = new AntlrStrictParser();

            foreach (var item in parser.Parse(cellText))
            {
                RealtyFromText realty = (RealtyFromText)item;
                if (realty.RealtyType != null && realty.RealtyType.Length > 0)
                {
                    RealEstateProperty realEstateProperty = new RealEstateProperty();
                    realEstateProperty.Text         = realty.GetSourceText();
                    realEstateProperty.type_raw     = realty.RealtyType;
                    realEstateProperty.square       = realty.Square;
                    realEstateProperty.country_raw  = realty.Country;
                    realEstateProperty.own_type_raw = realty.OwnType;
                    //???  = realty.RealtyShare; // nowhere to write to
                    realEstateProperty.own_type_by_column = ownTypeByColumn;
                    person.RealEstateProperties.Add(realEstateProperty);
                }
            }
        }
Example #18
0
        public ActionResult Sell([Bind(Include = "id,Address,Latitude,Longitude,OriginalSaleAmount,SoldAmount,SaleDate,CategoryId")] RealEstateProperty realEstateProperty)
        {
            RealEstateProperty realEstatePropertyVal = db.RealEstateProperties.Find(realEstateProperty.id);

            realEstatePropertyVal.SaleDate   = DateTime.Now;
            realEstatePropertyVal.SoldAmount = realEstateProperty.SoldAmount;
            if (ModelState.IsValid)
            {
                db.RealEstateProperties.AddOrUpdate(realEstatePropertyVal);
                db.SaveChanges();
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Property", db.RealEstateProperties.Find(realEstateProperty.id)));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "name", realEstateProperty.CategoryId);
            return(View(realEstateProperty));
        }
Example #19
0
        public ActionResult Sell(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            if (realEstateProperty == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "name", realEstateProperty.CategoryId);
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_sellProperty", realEstateProperty));
            }
            else
            {
                return(View(realEstateProperty));
            }
        }
Example #20
0
        public ActionResult CancelSell(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            if (realEstateProperty == null)
            {
                return(HttpNotFound());
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_property", realEstateProperty));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        void ParseRealtiesDistributedByColumns(string ownTypeByColumn, string realtyTypeFromColumnTitle, string cellText, Person person)
        {
            foreach (var bulletText in FindBullets(cellText))
            {
                RealEstateProperty realEstateProperty = new RealEstateProperty();
                realEstateProperty.Text               = bulletText;
                realEstateProperty.type_raw           = realtyTypeFromColumnTitle;
                realEstateProperty.own_type_by_column = ownTypeByColumn;
                var match = Regex.Match(bulletText, ".*\\s(\\d+[.,]\\d+)\\sкв.м", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    realEstateProperty.square = DataHelper.ConvertSquareFromString(match.Groups[1].ToString());
                }

                decimal?square = DataHelper.ParseSquare(bulletText);
                if (square.HasValue)
                {
                    realEstateProperty.square = square;
                }

                person.RealEstateProperties.Add(realEstateProperty);
            }
        }
        public async Task <RealEstateProperty> EditRealEsateProperty(RealEstateProperty realEstateProperty)
        {
            if (realEstateProperty == null)
            {
                throw new ArgumentNullException(nameof(realEstateProperty));
            }
            var realEstatePropertyData = RealEstateContext.RealEstateProperty
                                         .FirstOrDefault(x => x.PropertyName == realEstateProperty.PropertyName && x.IsActive);

            if (realEstatePropertyData == null)
            {
                throw new InvalidOperationException(Constants.PropertyNotExistsMessage);
            }

            realEstatePropertyData.UpdatedDate         = DateTime.Now;
            realEstatePropertyData.PropertyAddress     = realEstateProperty.PropertyAddress;
            realEstatePropertyData.PropertyDescription = realEstateProperty.PropertyDescription;
            realEstatePropertyData.PropertyValue       = realEstateProperty.PropertyValue;

            await RealEstateContext.SaveChangesAsync();

            return(realEstatePropertyData);
        }
Example #23
0
        public ActionResult CustomEditConfirm(int id, String Address, String Latitude, String Longitude, String OriginalSaleAmount, int CategoryId)
        {
            RealEstateProperty realEstateProperty = db.RealEstateProperties.Find(id);

            realEstateProperty.Address            = Address;
            realEstateProperty.Latitude           = ((String.IsNullOrEmpty(Latitude) || Latitude.Equals("null")) ? (double?)null : Convert.ToDouble(Latitude));
            realEstateProperty.Longitude          = ((String.IsNullOrEmpty(Longitude) || Longitude.Equals("null")) ? (double?)null : Convert.ToDouble(Longitude));
            realEstateProperty.OriginalSaleAmount = ((String.IsNullOrEmpty(OriginalSaleAmount) || OriginalSaleAmount.Equals("null")) ? (decimal?)null : Convert.ToDecimal(OriginalSaleAmount));
            realEstateProperty.CategoryId         = CategoryId;
            if (ModelState.IsValid)
            {
                db.RealEstateProperties.AddOrUpdate(realEstateProperty);
                db.SaveChanges();
                if (Request.IsAjaxRequest())
                {
                    return(Content(""));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(RedirectToAction("Index"));
        }
        public void Create(string district, int size, int?year, int price, string realEstateType, string buildingType, int?floor, int?maxFloors)
        {
            if (district == null)
            {
                return;
            }

            var property = new RealEstateProperty()
            {
                Size  = size,
                Price = price,
                Floor = floor,
                TotalNumberOfFloors = maxFloors,
                YearOfConstruction  = year
            };

            if (property.YearOfConstruction < 1800)
            {
                property.YearOfConstruction = null;
            }

            if (property.Floor <= 0)
            {
                property.Floor = null;
            }

            if (property.TotalNumberOfFloors <= 0)
            {
                property.TotalNumberOfFloors = null;
            }

            //District Set Up
            var districtEntity = this.db.Districts.FirstOrDefault(x => x.Name.Trim() == district);

            if (districtEntity == null)
            {
                districtEntity = new District()
                {
                    Name = district
                };
            }

            property.District = districtEntity;

            //BuildingType Set Up
            var buildingTypeEntity = this.db.BuildingTypes.FirstOrDefault(x => x.Name.Trim() == buildingType);

            if (buildingTypeEntity == null)
            {
                buildingTypeEntity = new BuildingType()
                {
                    Name = buildingType
                };
            }

            property.BuildingType = buildingTypeEntity;

            //PropertyType Set Up
            var realEstateTypeEntity = this.db.RealEstateTypes.FirstOrDefault(x => x.Name.Trim() == realEstateType);

            if (realEstateTypeEntity == null)
            {
                realEstateTypeEntity = new RealEstateType()
                {
                    Name = realEstateType
                };
            }

            property.RealEstateType = realEstateTypeEntity;

            this.db.RealEstateProperties.Add(property);
            this.db.SaveChanges();

            this.UpdateTags(property.Id);
        }
Example #25
0
        public void Create(string district, int size, int?year, int price, string propertyType, string buildingType, int?floor,
                           int?maxFloors)
        {
            if (district == null)
            {
                throw new ArgumentNullException(nameof(district));
            }

            var property = new RealEstateProperty()
            {
                Size  = size,
                Price = price,
                Year  = year < 1800 ? null : year,
                Floor = floor,
                TotalNumberOfFloors = maxFloors
            };

            if (property.Floor < 0)
            {
                property.Floor = null;
            }

            if (property.TotalNumberOfFloors <= 0)
            {
                property.TotalNumberOfFloors = null;
            }
            /// District
            var districtEntity = this.db.Districts.FirstOrDefault(d => d.Name.Trim() == district.Trim());

            if (districtEntity == null)
            {
                districtEntity = new District {
                    Name = district,
                };
            }
            property.District = districtEntity;

            /// Property Type
            var propertyTypeEntity = this.db.PropertyTypes.FirstOrDefault(pt => pt.Name.Trim() == propertyType.Trim());

            if (propertyTypeEntity == null)
            {
                propertyTypeEntity = new PropertyType {
                    Name = propertyType
                };
            }
            property.PropertyType = propertyTypeEntity;

            /// Building Type
            var buildingTypeEntity = this.db.BuildingTypes.FirstOrDefault(bt => bt.Name.Trim() == buildingType.Trim());

            if (buildingTypeEntity == null)
            {
                buildingTypeEntity = new BuildingType {
                    Name = buildingType
                };
            }

            property.BuildingType = buildingTypeEntity;


            this.db.RealEstateProperties.Add(property);
            this.db.SaveChanges();

            /// After db.SaveChanges is called, the property receives an Id and we can access it
            this.UpdateTags(property.Id);
        }
        public async Task <(RealEstatePropertiesResponse, RealEstateErrorCodes)> FormatAsync(string customerId, string spendRuleId)
        {
            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            if (string.IsNullOrEmpty(spendRuleId))
            {
                throw new ArgumentNullException(nameof(spendRuleId));
            }

            var customerProfile = await _cpClient.CustomerProfiles.GetByCustomerIdAsync(customerId);

            if (customerProfile.ErrorCode == CustomerProfileErrorCodes.CustomerProfileDoesNotExist)
            {
                return(null, RealEstateErrorCodes.CustomerProfileDoesNotExist);
            }

            var result = await _emaarPropertyIntegrationClient.Api.GetPendingInvoicePaymentsAsync(new GetPendingInvoicePaymentsRequestModel
            {
                Email = customerProfile.Profile.Email
            });

            if (!string.IsNullOrEmpty(result.ErrorCode))
            {
                _log.Error(message: "SalesForce returned error when tried to get pending installments for customer",
                           context: new { customerId, result.ErrorCode });

                return(null, RealEstateErrorCodes.SalesForceError);
            }

            var realEstateProperties = new List <RealEstateProperty>();

            foreach (var property in result.PendingInstallments)
            {
                var realEstateProperty = new RealEstateProperty
                {
                    Name        = property.LocationCode,
                    Instalments = new List <RealEstateInstalments>()
                };

                foreach (var instalment in property.InvoiceDetail)
                {
                    var eligibilityEngineResponse = await _eligibilityEngineClient.ConversionRate.GetAmountBySpendRuleAsync(
                        new ConvertAmountBySpendRuleRequest
                    {
                        CustomerId   = Guid.Parse(customerId),
                        Amount       = instalment.InvoiceAmountRemain,
                        FromCurrency = instalment.InvoiceCurrencyCode,
                        SpendRuleId  = Guid.Parse(spendRuleId),
                        ToCurrency   = _settingsService.GetEmaarTokenName()
                    });

                    if (eligibilityEngineResponse.ErrorCode == EligibilityEngineErrors.ConversionRateNotFound)
                    {
                        return(null, RealEstateErrorCodes.ConversionRateNotFound);
                    }

                    if (eligibilityEngineResponse.ErrorCode == EligibilityEngineErrors.SpendRuleNotFound)
                    {
                        return(null, RealEstateErrorCodes.SpendRuleNotFound);
                    }

                    realEstateProperty.Instalments.Add(new RealEstateInstalments
                    {
                        Name             = instalment.InvoiceDescription,
                        AmountInFiat     = instalment.InvoiceAmountRemain,
                        AmountInTokens   = eligibilityEngineResponse.Amount,
                        FiatCurrencyCode = instalment.InvoiceCurrencyCode,
                        DueDate          = instalment.DueDate,
                        Id = ComposeRealEstateId(instalment.LocationCode, instalment.AccountNumber, instalment.CustomerTrxId, instalment.InstallmentType, instalment.OrgId)
                    });
                }

                realEstateProperties.Add(realEstateProperty);
            }

            return(new RealEstatePropertiesResponse {
                RealEstateProperties = realEstateProperties
            },
                   RealEstateErrorCodes.None);
        }
        public void Create(int size, int?floor, int?maxFloorCount, string district, string propertyType, string buildingType, int?year, int price)
        {
            if (district == null)
            {
                return;
            }

            var property = new RealEstateProperty
            {
                Size  = size,
                Price = price,
                Year  = year,
                Floor = floor,
                TotalNumberOfFloors = maxFloorCount
            };

            if (year <= 0)
            {
                property.Year = null;
            }

            if (floor == 0)
            {
                property.Floor = null;
            }

            if (maxFloorCount == 0)
            {
                property.TotalNumberOfFloors = null;
            }


            #region District
            //Distrinct

            var currDistrict = this._districts.FirstOrDefault(x => x.Name == district);

            if (currDistrict == null)
            {
                currDistrict = new District
                {
                    Name = district,
                };

                this._districts.Add(currDistrict);
            }

            property.District = currDistrict;
            #endregion

            #region BuildingType
            //Building

            var currBuildingType = this._buildingTypes
                                   .FirstOrDefault(x => x.Name.Trim() == buildingType.Trim());

            if (currBuildingType == null)
            {
                currBuildingType = new BuildingType
                {
                    Name = buildingType
                };

                this._buildingTypes.Add(currBuildingType);
            }

            property.BuildingType = currBuildingType;
            #endregion

            #region PropertyType
            //PropertyTupe

            var currPropertyType = this._propertyTypes
                                   .FirstOrDefault(x => x.Name.Trim() == propertyType.Trim());

            if (currPropertyType == null)
            {
                currPropertyType = new PropertyType
                {
                    Name = propertyType
                };

                this._propertyTypes.Add(currPropertyType);
            }

            property.PropertyType = currPropertyType;
            #endregion

            this._db.Add(property);
        }
Example #28
0
        public void Create(string district, int size, int?year, int price, string propertyType, string buildingType, int?floor, int?maxFloors)
        {
            if (district == null)
            {
                throw new ArgumentNullException(nameof(district));
            }

            var property = new RealEstateProperty
            {
                Size  = size,
                Price = price,
                Year  = year,
                Floor = floor,
                TotalNumberOfFloors = maxFloors,
            };

            if (property.Year < 1800)
            {
                property.Year = null;
            }

            if (property.Floor <= 0)
            {
                property.Floor = null;
            }

            if (property.TotalNumberOfFloors <= 0)
            {
                property.TotalNumberOfFloors = null;
            }

            //DistrictType
            var districtEntity = this.db.Districts
                                 .FirstOrDefault(x => x.Name.Trim() == district.Trim());

            if (districtEntity == null)
            {
                districtEntity = new District {
                    Name = district
                };
            }
            property.District = districtEntity;

            //BuildingType
            var buildingTypeEntity = this.db.BuildingTypes
                                     .FirstOrDefault(x => x.Name.Trim() == buildingType.Trim());

            if (buildingTypeEntity == null)
            {
                buildingTypeEntity = new BuildingType {
                    Name = buildingType
                };
            }
            property.BuildingType = buildingTypeEntity;

            //PropertyType
            var propertyTypeEntity = this.db.PropertyTypes
                                     .FirstOrDefault(x => x.Name.Trim() == propertyType.Trim());

            if (propertyTypeEntity == null)
            {
                propertyTypeEntity = new PropertyType {
                    Name = propertyType
                };
            }
            property.PropertyType = propertyTypeEntity;

            this.db.RealEstateProperties.Add(property);
            this.db.SaveChanges();

            this.UpdateTags(property.Id);
        }
        public void Create(double?size, int?floor, int?totalFloors, string district,
                           int?year, string propertyType, string buildingType, decimal price)
        {
            if (district == null)
            {
                throw new InvalidOperationException(nameof(district));
            }
            if (price <= 0)
            {
                throw new InvalidOperationException(nameof(price));
            }

            var prop = new RealEstateProperty
            {
                Size  = size <= 0 ? null : size,
                Floor = floor <= 0 ? null : floor,
                TotalNumberOfFloors = totalFloors <= 0 ? null : totalFloors,
                BuildingYear        = year <= 1800 ? null : year,
                Price = price
            };
            //District
            var districtDb = this.db.Districts.FirstOrDefault(x => x.Name.Trim() == district.Trim());

            if (districtDb == null)
            {
                districtDb = new District()
                {
                    Name = district
                };
            }
            prop.District = districtDb;

            //PropertyType
            var propTypeDb = db.PropertyTypes.FirstOrDefault(x => x.Type.Trim().ToLower() == propertyType.Trim().ToLower());

            if (propTypeDb == null)
            {
                propTypeDb = new PropertyType()
                {
                    Type = propertyType
                };
            }
            prop.PropertyType = propTypeDb;

            //BuildingType
            var buildingTypeDb = db.BuildingTypes.FirstOrDefault(x => x.Type.Trim().ToLower() == buildingType.Trim().ToLower());

            if (buildingTypeDb == null)
            {
                buildingTypeDb = new BuildingType()
                {
                    Type = buildingType
                };
            }
            prop.BuildingType = buildingTypeDb;

            db.RealEstateProperties.Add(prop);
            db.SaveChanges();

            UpdateTags(prop.Id);
        }
        private void ParseRealEstateTable(Table table, PublicServant person, string ownTypeByColumn)
        {
            var    rows = table.Descendants <TableRow>().ToList().Skip(1);
            string currentRealEstateType = "";

            foreach (var row in rows)
            {
                var cells           = row.Descendants <TableCell>().ToList();
                var gridSpan        = cells[0].TableCellProperties.GetFirstChild <GridSpan>();
                var mergedColsCount = (gridSpan == null) ? 1 : (int)gridSpan.Val;
                var text            = cells[0].InnerText;

                if (mergedColsCount > 1)
                {
                    currentRealEstateType = text;
                    continue;
                }

                var textStr = cells[1].InnerText;
                if (textStr.OnlyRussianLowercase() == "неимеет")
                {
                    continue;
                }
                var areaStr    = cells[2].InnerText;
                var countryStr = cells[3].InnerText;
                var ownerStr   = cells[4].InnerText;

                var owners = ownerStr.Split(",").ToList();
                var shares = owners.Where(x => x.Contains(" доля") || x.Contains(" доли")).ToList();
                owners = owners.Where(x => !(x.Contains(" доля") || x.Contains(" доли"))).ToList();

                if (shares.Count != owners.Count && shares.Count > 0)
                {
                    throw new SmartParserException("shares.Count != owners.Count in SovetFederaciiDocxScheme");
                }

                if (shares.Count < owners.Count)
                {
                    shares = Enumerable.Repeat <string>(null, owners.Count - shares.Count).ToList();
                }

                var zippedOwners = owners.Zip(shares);

                foreach (var pair in zippedOwners)
                {
                    var owner = pair.First;
                    var share = pair.Second;
                    var realEstateProperty = new RealEstateProperty
                    {
                        Text               = textStr,
                        square             = DataHelper.ParseSquare(areaStr),
                        type_raw           = currentRealEstateType,
                        square_raw         = ParserBase.NormalizeRawDecimalForTest(areaStr),
                        country_raw        = DataHelper.ParseCountry(countryStr),
                        own_type_by_column = ownTypeByColumn
                    };

                    if (share != default)
                    {
                        realEstateProperty.own_type_raw = share;
                    }

                    var relationType = DataHelper.ParseRelationType(owner, false);
                    if (DataHelper.IsRelativeInfo(owner))
                    {
                        var relative = GetPersonRelative(person, relationType);
                        relative.RealEstateProperties.Add(realEstateProperty);
                    }
                    else
                    {
                        person.RealEstateProperties.Add(realEstateProperty);
                    }
                }
            }
        }