示例#1
0
        public RentalProperty UpdateThisRentalProperty(int id, RentalProperty updatesForRentalProperty)
        {
            using (var db = new SqlConnection(_connectionString))
            {
                var sql = @"UPDATE [dbo].[Rentals]
                          SET
                          [Street] = @Street
                          ,[City] = @City
                          ,[State] = @State
                          ,[Zip] = @Zip
                          ,[Bedrooms] = @Bedrooms
                          ,[Baths] = @Baths
                          ,[Sqft]= @Sqft
                          ,[HasTenants] = @HasTenants
                          ,[IsActive] = @IsActive
                          ,[imgUrl] = @imgUrl
                          
                          output inserted.*
                          WHERE id = @id";

                updatesForRentalProperty.Id = id;

                var newUpdatedRentalProperty = db.QueryFirst <RentalProperty>(sql, updatesForRentalProperty);

                return(newUpdatedRentalProperty);
            }
        }
示例#2
0
        public bool UserCanManageRentalProperty(RentalProperty property, User user)
        {
            if (user.UserType == UserType.admin)
            {
                return true;
            }

            if (user.UserType == UserType.manager)
            {
                if (user.Agent == property.Agent)
                {
                    return true;
                }
            }

            if (user.UserType == UserType.employee)
            {
                if (user.Agent == property.Agent)
                {
                    return true;
                }
            }

            return false;
        }
示例#3
0
        public RentalProperty AddNewRentalProperty(RentalProperty newRentalProperty)
        {
            using (var db = new SqlConnection(_connectionString))
            {
                var sql = @"INSERT INTO [Rentals]
                          ([Street]
                          ,[City]
                          ,[State]
                          ,[Zip]
                          ,[Bedrooms]
                          ,[Baths]
                          ,[Sqft]
                          ,[HasTenants]
                          ,[IsActive]
                          ,[imgUrl]
                          )
                          output inserted.*
                          VALUES
                          (@Street
                          ,@City
                          ,@State
                          ,@Zip
                          ,@Bedrooms
                          ,@Baths
                          ,@Sqft
                          ,@HasTenants
                          ,@IsActive)
                          ,@imgUrl";

                return(db.QueryFirst <RentalProperty>(sql, newRentalProperty));
            }
        }
示例#4
0
        public static void Add(RentalProperty rental)
        {
            var context = new RentalsContext();

            context.RentalProperties.Add(rental);
            context.SaveChanges();
        }
示例#5
0
        public static void AddRental(RentalProperty property)
        {
            var lastId = Rentals.Max(r => r.Id);

            property.Id = lastId + 1;
            Rentals.Add(property);
        }
示例#6
0
        private async Task HandleAsync(RentalPropertyCreatedEvent @event) // This event is not be listened to as it is integrated with RentalAppApprove evnt in the ABOVE!!!
        {
            //var ownerAddress = new OwnerAddress(@event.StreetNum, @event.City, @event.StateProvince, @event.City, @event.ZipPostCode);

            var address = new Address(@event.StreetNum, @event.City, @event.StateProvince, @event.City, @event.ZipPostCode);

            // need to add owner infomration

            //var owner = new RentalPropertyOwner(@event.OwnerFirstName, @event.OwnerLastName, @event.OwnerContactEmail,
            //   @event.OwnerContactTel, @event.OwnerContactOther,  @event.PropertyId, ownerAddress, DateTime.Now, DateTime.Now);

            var rentalProperty = new RentalProperty(@event.PropertyId, DateTime.Now, DateTime.Now, 0, @event.PropertyName, @event.Type, @event.PropertyBuildYear,
                                                    @event.IsShared, "Rented", @event.IsBasementSuite, @event.NumberOfBedrooms, @event.NumberOfBathrooms, @event.NumberOfLayers, @event.NumberOfParking,
                                                    @event.TotalLivingArea, "", @event.PropertyManagerUserName, address);

            _context.RentalProperty.Add(rentalProperty);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //throw new NotImplementedException();
        }
示例#7
0
        public ActionResult DeleteConfirmed(int id)
        {
            RentalProperty rentalProperty = db.RentalProperty.Find(id);

            db.RentalProperty.Remove(rentalProperty);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#8
0
        public RentalPropertyViewModel(RentalProperty rentalProperty)
        {
            if (rentalProperty == null)
            {
                throw new ArgumentNullException(nameof(rentalProperty));
            }

            this.Id   = rentalProperty.Id;
            this.Name = rentalProperty.Name;
        }
示例#9
0
 public ActionResult Edit([Bind(Include = "Id,StreetAddress,ZipCode,PropertyManagerId")] RentalProperty rentalProperty)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rentalProperty).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PropertyManagerId = new SelectList(db.PropertyManager, "Id", "EmailAddress", rentalProperty.PropertyManagerId);
     return(View(rentalProperty));
 }
示例#10
0
 public IActionResult Create(RentalProperty rental)
 {
     try
     {
         RentalsManager.Add(rental);
         return(Redirect("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#11
0
        public async Task <RentalProperty> EditRentalProperty(int id, RentalProperty property)
        {
            RentalProperty rental = null;

            rental    = _db.RentalProperties.AsNoTracking().FirstOrDefault(m => m.Id == id);
            rental    = property;
            rental.Id = id;

            _db.RentalProperties.Update(rental);
            await _db.SaveChangesAsync();

            return(rental);
        }
示例#12
0
 public IActionResult Create(RentalProperty rental)
 {
     try
     {
         // TODO: Add insert logic here
         PropertyManager.AddRental(rental);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
示例#13
0
        // GET: RentalProperties/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentalProperty rentalProperty = db.RentalProperty.Find(id);

            if (rentalProperty == null)
            {
                return(HttpNotFound());
            }
            return(View(rentalProperty));
        }
示例#14
0
        // GET: RentalProperties/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RentalProperty rentalProperty = db.RentalProperty.Find(id);

            if (rentalProperty == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PropertyManagerId = new SelectList(db.PropertyManager, "Id", "EmailAddress", rentalProperty.PropertyManagerId);
            return(View(rentalProperty));
        }
示例#15
0
        // [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
        public async Task <IActionResult> AddRentalProperty([FromForm] RentalProperty property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _manager.AddRentalProperty(property);

            if (result != null)
            {
                return(Ok(result));
            }

            return(BadRequest());
        }
示例#16
0
        // [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
        public async Task <IActionResult> EditRentalProperty([FromRoute] int id, [FromBody] RentalProperty property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _manager.EditRentalProperty(id, property);

            if (result != null)
            {
                return(Ok(result));
            }

            return(BadRequest());
        }
示例#17
0
        private async Task HandleAsync(PropertyCreatedEvent @event)
        {
            //var p = _context.RentalProperty.FirstOrDefault(r => r.Id == 2); // Test code

            var ownerAddress = new OwnerAddress(@event.OwnerStreetNum, @event.OwnerCity, @event.OwnerStateProvince, @event.OwnerCountry, @event.OwnerZipPostCode);

            var owner = new RentalPropertyOwner(@event.OwnerId, @event.OwnerFirstName, @event.OwnerLastName, @event.OwnerContactEmail, @event.OwnerContactTel, @event.OwnerContactOther, ownerAddress, DateTime.Now, DateTime.Now);

            var owners = new List <RentalPropertyOwner>();

            owners.Add(owner);

            await _context.AddAsync(owner);

            var address = new Address(
                @event.StreetNum, @event.City, @event.StateProvince, @event.Country, @event.ZipPostCode);

            int geoId = 0;

            geoId = getGeoId(@event.City);

            var property = new RentalProperty(
                @event.PropertyId, @event.PropertyName, @event.Type, @event.PropertyManagerUserName, @event.PropertyBuildYear,
                @event.IsShared, @event.IsBasementSuite, @event.NumberOfBedrooms, @event.NumberOfBathrooms,
                @event.NumberOfLayers, @event.NumberOfParking, @event.TotalLivingArea, "", DateTime.Now,
                DateTime.Now, address, geoId, owners);


            await _context.AddAsync(property);

            try
            {
                await _context.SaveChangesAsync();

                Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);
            }
            catch (Exception ex)
            {
                //throw ex;
                //string messageId = messageObject.Property("MessageId") != null ? messageObject.Property("MessageId").Value<string>() : "[unknown]";
                Log.Error(ex, "Error while handling {MessageType} message with id {MessageId}.", @event.MessageType, @event.MessageId);
            }

            //throw new NotImplementedException();

            //Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);

            //var msgDetails = new MessageDetails();

            //msgDetails.PrincicipalId = @event.PropertyId;
            //msgDetails.PrincipalType = "Property";
            //msgDetails.PrincipalNameDesc = @event.PropertyName;
            //msgDetails.OperationType = "Create";

            //var details = msgDetails.ToBsonDocument();

            //var msg = new Message(@event.MessageId, "Asset Management", details, "asset_created", "asset_created.*", "Subscription", DateTime.Now);

            //var messageLoggingService = new MessageLoggingService();

            //await messageLoggingService.LogMessage(msg);
        }
示例#18
0
        //------------------------------------
        // Calculations
        //------------------------------------
        private void CalculateAll()
        {
            string resultText;

            //RentalProperty
            double currentRent = 0.0d;

            double.TryParse(txtCurrentRent.Text, System.Globalization.NumberStyles.Currency, null, out currentRent);

            string rentalPaymentFrequency = cmbRentalPaymentFrequency.Text;

            RentalProperty rentalProperty = new RentalProperty(currentRent, rentalPaymentFrequency);

            //PurchaseProperty
            double purchasePrice = 0.0d;

            double.TryParse(txtPurchasePrice.Text, System.Globalization.NumberStyles.Currency, null, out purchasePrice);

            double annualCosts = 0.0d;

            double.TryParse(txtAnnualCosts.Text, System.Globalization.NumberStyles.Currency, null, out annualCosts);

            PurchaseProperty purchaseProperty = new PurchaseProperty(purchasePrice, annualCosts);

            //Customer
            double afterTaxIncome = 0.0d;;

            double.TryParse(txtAfterTaxIncome.Text, System.Globalization.NumberStyles.Currency, null, out afterTaxIncome);

            double annualExpenses = 0.0d;;

            double.TryParse(txtAnnualExpenses.Text, System.Globalization.NumberStyles.Currency, null, out annualExpenses);

            Customer customer = new Customer(afterTaxIncome, annualExpenses);


            //Bank
            double savings = 0.0d;

            double.TryParse(txtSavings.Text, System.Globalization.NumberStyles.Currency, null, out savings);

            double interestOnSavingsRateRaw       = 0.0d;
            string interestOnSavingsRateRawString = txtInterestOnSavings.Text;

            interestOnSavingsRateRawString = interestOnSavingsRateRawString.Replace('%', ' ').Trim();
            double.TryParse(interestOnSavingsRateRawString, out interestOnSavingsRateRaw);
            double interestOnSavingsRate = interestOnSavingsRateRaw / 100;//Turn into a percentage

            double mortgageRateRaw       = 0.0d;
            string mortgageRateRawString = txtMortgageRate.Text;

            mortgageRateRawString = mortgageRateRawString.Replace('%', ' ').Trim();
            double.TryParse(mortgageRateRawString, out mortgageRateRaw);
            double mortgageRate = mortgageRateRaw / 100;//Turn into a percentage

            int term = 0;

            int.TryParse(cmbMortgageTerm.Text, out term);

            BankAccount bankAccount = new BankAccount(savings, interestOnSavingsRate, mortgageRate, term);


            double[] accountsByYearRenting;
            double[] accountsByYearBuying;

            accountsByYearRenting = bankAccount.BalanceRenting(rentalProperty, customer.IncomeAfterExpenses, term);
            accountsByYearBuying  = bankAccount.BalanceBuying(purchaseProperty, customer.IncomeAfterExpenses, term);

            //Heading of Result Text
            resultText  = "Result" + Environment.NewLine;
            resultText += "Total Assets Final Year Renting: " + accountsByYearRenting[accountsByYearRenting.Length - 1].ToString("C") + Environment.NewLine;


            double totalAssetsFinalYearBuying = (accountsByYearBuying[accountsByYearBuying.Length - 1] + purchaseProperty.PurchasePrice);

            resultText += "Total Assets Final Year Buying: " + totalAssetsFinalYearBuying.ToString("C") + Environment.NewLine;



            resultText += Environment.NewLine;

            resultText += "Current Savings: " + bankAccount.CurrentSavings.ToString() + Environment.NewLine;
            resultText += Environment.NewLine;


            //Renting Property
            resultText += "Rent Annually: " + rentalProperty.AnnualRent.ToString() + Environment.NewLine;

            resultText += "Account Balance Renting" + Environment.NewLine;
            for (int i = 0; i < accountsByYearRenting.Length; i++)
            {
                resultText += "Year " + i + ": " + accountsByYearRenting[i].ToString("C") + Environment.NewLine;
            }
            resultText += Environment.NewLine;


            //Purchasing property

            resultText += "Account Balance Buying" + Environment.NewLine;
            for (int i = 0; i < accountsByYearBuying.Length; i++)
            {
                resultText += "Year " + i + ": " + accountsByYearBuying[i].ToString("C") + Environment.NewLine;
            }
            resultText += Environment.NewLine;



            rtxResult.Text = resultText;
        }
示例#19
0
        public static object EditProperty(RequestModel request)
        {
            var connection = new MySqlConnection(ConfigurationManager.AppSettings["MySqlDBConn"].ToString());
            var compiler   = new MySqlCompiler();
            var db         = new QueryFactory(connection, compiler);

            SuccessResponse successResponseModel = new SuccessResponse();

            db.Connection.Open();
            using (var scope = db.Connection.BeginTransaction())
            {
                try
                {
                    var    test = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(Convert.ToString(request.RequestData));
                    object PropertyID;
                    test.TryGetValue("PropertyID", out PropertyID);
                    int _PropertyID = Convert.ToInt32(PropertyID);

                    object PropertyType;
                    test.TryGetValue("PropertyType", out PropertyType);
                    string _PropertyType = PropertyType.ToString();
                    test.Remove("PropertyType");
                    object PropertyPics;
                    test.TryGetValue("PropertyPics", out PropertyPics);
                    List <string> _PropertyPics = PropertyPics as List <string>;
                    test.Remove("PropertyPics");
                    if (_PropertyPics != null && _PropertyPics.Count > 0)
                    {
                        //convert and add key
                    }

                    object PropertyVideos;
                    test.TryGetValue("PropertyVideos", out PropertyVideos);
                    List <string> _PropertyVideos = PropertyVideos as List <string>;
                    test.Remove("PropertyVideos");
                    if (_PropertyVideos != null && _PropertyVideos.Count > 0)
                    {
                        //convert and add key
                    }

                    object Documents;
                    test.TryGetValue("Documents", out Documents);
                    List <string> _Documents = Documents as List <string>;
                    test.Remove("Documents");
                    if (_Documents != null && _Documents.Count > 0)
                    {
                        //convert and add key
                    }
                    if (_PropertyType == "D")
                    {
                        object _Developmental;
                        test.TryGetValue("Developmental", out _Developmental);
                        test.Remove("Developmental");
                        Dictionary <string, object> DevelopmentalProperty = JsonConvert
                                                                            .DeserializeObject <Dictionary
                                                                                                <string, object> >(_Developmental.ToString());


                        if (DevelopmentalProperty != null)
                        {
                            DevelopmentalProperty.Add("PropertyID", _PropertyID);
                            var resdevprop = db.Query("developmental").Where("PropertyID", _PropertyID).Update(DevelopmentalProperty);
                        }

                        object DevelopmentalPrediction;
                        test.TryGetValue("DevelopmentalPrediction", out DevelopmentalPrediction);
                        test.Remove("DevelopmentalPrediction");
                        List <Dictionary <string, object> > _DevelopmentalPrediction = JsonConvert
                                                                                       .DeserializeObject <List <Dictionary
                                                                                                                 <string, object> > >(DevelopmentalPrediction.ToString());

                        if (_DevelopmentalPrediction != null)
                        {
                            foreach (var pd in _DevelopmentalPrediction)
                            {
                                object _PredictionID;
                                pd.TryGetValue("PredictionID", out _PredictionID);
                                if (_PredictionID == null)
                                {
                                    pd.Add("PropertyID", _PropertyID);
                                    var resPdRN = db.Query("developmentalprediction").Insert(pd);
                                }
                            }
                        }
                    }
                    else if (_PropertyType == "R")
                    {
                        object RentalProperty;
                        test.TryGetValue("RentalProperty", out RentalProperty);
                        test.Remove("RentalProperty");
                        List <Dictionary <string, object> > _RentalProperty = JsonConvert
                                                                              .DeserializeObject <List <Dictionary
                                                                                                        <string, object> > >(RentalProperty.ToString());
                        if (_RentalProperty != null)
                        {
                            foreach (var ren in _RentalProperty)
                            {
                                object _RentalPropertyid;
                                ren.TryGetValue("RentalPropertyID", out _RentalPropertyid);
                                if (_RentalPropertyid == null)
                                {
                                    object RentalContract;
                                    ren.TryGetValue("RentalContract", out RentalContract);
                                    List <string> _RentalContract = RentalContract as List <string>;
                                    ren.Remove("RentalContract");
                                    if (_RentalContract != null && _RentalContract.Count > 0)
                                    {
                                        //convert and add key
                                    }
                                    ren.Add("PropertyID", _PropertyID);
                                    var resRental = db.Query("RentalProperty").Insert(ren);
                                }
                            }
                        }
                    }
                    object PropertyPrediction;
                    test.TryGetValue("PropertyPrediction", out PropertyPrediction);
                    test.Remove("PropertyPrediction");
                    List <Dictionary <string, object> > PredictionRentalProperty = JsonConvert
                                                                                   .DeserializeObject <List <Dictionary
                                                                                                             <string, object> > >(PropertyPrediction.ToString());
                    if (PredictionRentalProperty != null)
                    {
                        foreach (var pd in PredictionRentalProperty)
                        {
                            object _PredictionID;
                            pd.TryGetValue("PredictionID", out _PredictionID);
                            if (_PredictionID == null)
                            {
                                pd.Add("PropertyID", _PropertyID);
                                var resPdRN = db.Query("propertyprediction").Insert(pd);
                            }
                        }
                    }

                    var query = db.Query("propertydetail").Where("PropertyID", _PropertyID).Update(test);

                    bool hasData = true;
                    scope.Commit();
                    successResponseModel = new SuccessResponse("", hasData, "Record Edited");
                }
                catch (Exception ex)
                {
                    scope.Rollback();
                    return(new ErrorResponse(ex.Message, HttpStatusCode.BadRequest));
                }

                return(successResponseModel);
            }
        }
示例#20
0
        public async Task <RentalProperty> AddRentalProperty(RentalProperty property)
        {
            if (property != null)
            {
                property.IsActive = true;

                IFormFile[] files     = new IFormFile[] { property.imageFile1, property.imageFile2, property.imageFile3, property.imageFile4 };
                string[]    fileLinks = new string[] { property.ImageLink1, property.ImageLink2, property.ImageLink3, property.ImageLink4 };

                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i] == null)
                    {
                        fileLinks[i] = "#";
                    }
                    else
                    {
                        fileLinks[i] = GetFileUploadBlobReturnsLink(files[i]);
                    }
                }
                property.ImageLink1 = fileLinks[0];
                property.ImageLink2 = fileLinks[1];
                property.ImageLink3 = fileLinks[2];
                property.ImageLink4 = fileLinks[3];

                //     var image = property.imageFile1;

                //     var imageFileName = image.FileName;
                //     string imageMimeType = image.ContentType;
                //     byte[] imageData = GetBytes(property.imageFile1);

                //    // property.ImageLink1 = _blob.UploadFileToBlob(imageFileName, imageData, imageMimeType);

                //     var image1 = property.imageFile2;

                //     var imageFileName2 = image1.FileName;
                //     string imageMimeType2 = image1.ContentType;
                //     byte[] imageData2 = GetBytes(image1);

                //    // property.ImageLink2 = _blob.UploadFileToBlob(imageFileName2, imageData2, imageMimeType2);

                //     var image2 = property.imageFile3;

                //     var imageFileName3 = image2.FileName;
                //     string imageMimeType3 = image2.ContentType;
                //     byte[] imageData3 = GetBytes(image2);

                //     //property.ImageLink3 = _blob.UploadFileToBlob(imageFileName3, imageData3, imageMimeType3);

                //      var videoFile = property.imageFile4;

                //     var videoFileName = videoFile.FileName;
                //     string videoFileMimeType = videoFile.ContentType;
                //     byte[] videoFileData = GetBytes(videoFile);

                //property.ImageLink4 = _blob.UploadFileToBlob(videoFileName, videoFileData, videoFileMimeType);
                _db.RentalProperties.Add(property);
                await _db.SaveChangesAsync();

                return(property);
            }

            return(null);
        }
示例#21
0
        public IActionResult UpdateThisRentalProperty(int id, RentalProperty updatesForRentalProperty)
        {
            var updatedRentalProperty = _repo.UpdateThisRentalProperty(id, updatesForRentalProperty);

            return(Ok(updatedRentalProperty));
        }
示例#22
0
        public IActionResult CreateNewRentalProperty(RentalProperty newRentalProperty)
        {
            var addNewRentalProperty = _repo.AddNewRentalProperty(newRentalProperty);

            return(Ok(newRentalProperty));
        }
示例#23
0
 public IActionResult Process(RentalProperty rental)
 {
     PropertyManager.AddRental(rental);
     return(Redirect("Index"));
 }
示例#24
0
        public static object SaveAddNewProperty(RequestModel request)
        {
            var connection = new MySqlConnection(ConfigurationManager.AppSettings["MySqlDBConn"].ToString());
            var compiler   = new MySqlCompiler();
            var db         = new QueryFactory(connection, compiler);

            SuccessResponse successResponseModel = new SuccessResponse();

            db.Connection.Open();
            using (var scope = db.Connection.BeginTransaction())
            {
                try
                {
                    var test = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(Convert.ToString(request.RequestData));

                    object PropertyType;
                    test.TryGetValue("PropertyType", out PropertyType);
                    string _PropertyType = PropertyType.ToString();

                    object PropertyPics;
                    test.TryGetValue("PropertyPics", out PropertyPics);
                    List <string> _PropertyPics = PropertyPics as List <string>;
                    test.Remove("PropertyPics");
                    if (_PropertyPics != null && _PropertyPics.Count > 0)
                    {
                        //convert and add key
                    }

                    object PropertyVideos;
                    test.TryGetValue("PropertyVideos", out PropertyVideos);
                    List <string> _PropertyVideos = PropertyVideos as List <string>;
                    test.Remove("PropertyVideos");
                    if (_PropertyVideos != null && _PropertyVideos.Count > 0)
                    {
                        //convert and add key
                    }

                    object Documents;
                    test.TryGetValue("Documents", out Documents);
                    List <string> _Documents = Documents as List <string>;
                    test.Remove("Documents");
                    if (_Documents != null && _Documents.Count > 0)
                    {
                        //convert and add key
                    }

                    object PropertyShare;
                    test.TryGetValue("PropertyShare", out PropertyShare);
                    test.Remove("PropertyShare");

                    object PropertyPrediction;
                    test.TryGetValue("PropertyPrediction", out PropertyPrediction);
                    test.Remove("PropertyPrediction");

                    object Developmental;
                    test.TryGetValue("Developmental", out Developmental);
                    test.Remove("Developmental");

                    object DevelopmentalPrediction;
                    test.TryGetValue("DevelopmentalPrediction", out DevelopmentalPrediction);
                    test.Remove("DevelopmentalPrediction");

                    object RentalProperty;
                    test.TryGetValue("RentalProperty", out RentalProperty);
                    test.Remove("RentalProperty");
                    // You can register the QueryFactory in the IoC container

                    var query = db.Query("propertydetail").AsInsert(test);

                    SqlKata.SqlResult compiledQuery = compiler.Compile(query);

                    //Inject the Identity in the Compiled Query SQL object
                    var sql = compiledQuery.Sql + "; SELECT @@IDENTITY as ID;";

                    //Name Binding house the values that the insert query needs
                    var IdentityKey = db.Select <string>(sql, compiledQuery.NamedBindings).FirstOrDefault();

                    Dictionary <string, object> _PropertyShare = JsonConvert.DeserializeObject <Dictionary <string, object> >(PropertyShare.ToString());
                    if (_PropertyShare != null)
                    {
                        _PropertyShare.Add("PropertyId", IdentityKey);
                        var resPropertyShare = db.Query("PropertyShare").Insert(_PropertyShare);
                    }

                    List <Dictionary <string, object> > _PropertyPrediction = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(PropertyPrediction.ToString());
                    if (_PropertyPrediction != null)
                    {
                        foreach (var pp in _PropertyPrediction)
                        {
                            pp.Add("PropertyId", IdentityKey);
                            var resPropertyShare = db.Query("PropertyPrediction").Insert(pp);
                        }
                    }
                    if (_PropertyType == "D")
                    {
                        Dictionary <string, object> _Developmental = JsonConvert.DeserializeObject <Dictionary <string, object> >(Developmental.ToString());
                        if (_Developmental != null)
                        {
                            _Developmental.Add("PropertyId", IdentityKey);
                            var resDevelopmental = db.Query("Developmental").Insert(_Developmental);
                        }

                        List <Dictionary <string, object> > _DevelopmentalPrediction = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(DevelopmentalPrediction.ToString());
                        if (_DevelopmentalPrediction != null)
                        {
                            foreach (var dp in _DevelopmentalPrediction)
                            {
                                dp.Add("PropertyId", IdentityKey);
                                var resDevelopmentalPrediction = db.Query("DevelopmentalPrediction").Insert(dp);
                            }
                        }
                    }

                    if (_PropertyType == "R")
                    {
                        Dictionary <string, object> _RentalProperty = JsonConvert.DeserializeObject <Dictionary <string, object> >(RentalProperty.ToString());
                        if (_RentalProperty != null)
                        {
                            object RentalContract;
                            _RentalProperty.TryGetValue("RentalContract", out RentalContract);
                            List <string> _RentalContract = RentalContract as List <string>;
                            _RentalProperty.Remove("RentalContract");
                            if (_RentalContract != null && _RentalContract.Count > 0)
                            {
                                //convert and add key
                            }

                            _RentalProperty.Add("PropertyId", IdentityKey);
                            var resRentalProperty = db.Query("RentalProperty").Insert(_RentalProperty);
                        }
                    }
                    bool hasData = true;
                    scope.Commit();
                    successResponseModel = new SuccessResponse("", hasData, "Record Saved");
                }
                catch (Exception ex)
                {
                    //Logger.WriteErrorLog(ex);
                    scope.Rollback();
                    return(new ErrorResponse(ex.Message, HttpStatusCode.BadRequest));
                }
            }
            return(successResponseModel);
        }
示例#25
0
        private async Task HandleAsync(RentalAppApprovedEvent @event)
        {
            var newTenant = new NewTenant(@event.UserName, @event.FirstName, @event.LastName, @event.ContactEmail,
                                          @event.ContactTelephone1, @event.ContactTelephone2, @event.ContactOthers, DateTime.Now, DateTime.Now);

            _context.Add(newTenant);

            //try
            //{
            //    await _context.SaveChangesAsync();
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}



            var rentalproperty = _context.RentalProperty.Include(a => a.Address).FirstOrDefault(a => a.OriginalId == @event.PropertyId); // Get related rental property

            //Note above: @event.ProeprtyId comes from the event and is the Id for rental property (in Marketing), it should be named OriginalId in RentalProperty in Lease service

            if (rentalproperty == null)
            {
                var address = new Address(@event.StreetNum, @event.City, @event.StateProvince, @event.Country, @event.ZipPostCode);

                var owners = new List <RentalPropertyOwner>();

                foreach (var owner in @event.PropertyOwners)
                {
                    var ownerAddress = new OwnerAddress(owner.OwnerStreetNum, owner.OwnerCity, owner.OwnerStateProvinc, owner.OwnerZipPostCode, owner.OwnerCountry);
                    var pOwner       = new RentalPropertyOwner(owner.PropertyOwnerId, owner.FirstName, owner.LastName, owner.ContactEmail, owner.ContactTelephone, owner.ContactOther, owner.RentalPropertyId, ownerAddress, DateTime.Now, DateTime.Now);
                    owners.Add(pOwner);
                }

//(IList<RentalPropertyOwner>)@event.PropertyOwners


                var newRentalProperty = new RentalProperty(@event.PropertyId, DateTime.Now, DateTime.Now, @event.ListingId, /*0,*/ @event.PropertyName, @event.Type, @event.PropertyBuildYear,
                                                           @event.IsShared, "Pending", @event.IsBasementSuite, @event.NumberOfBedrooms, @event.NumberOfBathrooms, @event.NumberOfLayers,
                                                           @event.NumberOfParking, @event.TotalLivingArea, @event.Notes, @event.PropertyManagerUserName, address, owners);

                _context.RentalProperty.Add(newRentalProperty);

                //try
                //{
                //    await _context.SaveChangesAsync();

                //    Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);
                //}
                //catch (Exception ex)
                //{
                //    //throw ex;
                //    Log.Error(ex, "Error while handling {MessageType} message with id {MessageId}.", @event.MessageType, @event.MessageId);
                //}
            }

            try
            {
                await _context.SaveChangesAsync();

                Log.Information("Message  {MessageType} with Id {MessageId} has been handled successfully", @event.MessageType, @event.MessageId);
            }
            catch (Exception ex)
            {
                //throw ex;
                Log.Error(ex, "Error while handling {MessageType} message with id {MessageId}.", @event.MessageType, @event.MessageId);
            }


            //throw new NotImplementedException();
        }
 public GetRentalPropertyByIdResponse(RentalProperty rentalProperty)
 {
     this.RentalProperty = rentalProperty;
 }
        /// <summary>
        /// Populates an instance of <see cref="Domain.Property"/> from
        /// information obtained from the local database.
        /// </summary>
        /// <param name="source">The information to use to populate the
        /// resulting object</param>
        /// <returns><paramref name="source"/> in the destination format</returns>
        public Property Map(PropertyInformation source)
        {
            PropertyType type           = (PropertyType)Enum.Parse(typeof(PropertyType), source.Type);
            Property     mappedProperty = null;
            Property     baseProperty   = new Property
            {
                Id          = source.PropertyId,
                Price       = source.Price,
                Description = source.Description,
                Agent       = new Agent
                {
                    Id          = source.AgentId,
                    FirstName   = source.AgentFirstName,
                    LastName    = source.AgentLastName,
                    Email       = source.AgentEmail,
                    PhoneNumber = source.AgentPhone
                },
                Address = new PropertyAddress
                {
                    Id      = source.AddressId,
                    Country = new Country
                    {
                        Id   = source.CountryId,
                        Name = source.Country
                    },
                    State = new State
                    {
                        Id           = source.StateId,
                        Name         = source.State,
                        Abbreviation = source.StateAbbreviation
                    },
                    City = new City
                    {
                        Id   = source.CityId,
                        Name = source.City
                    },
                    Suburb = new Suburb
                    {
                        Id       = source.SuburbId,
                        Name     = source.Suburb,
                        PostCode = source.PostCode
                    },
                    StreetAddress = source.StreetAddress
                }
            };

            switch (type)
            {
            case PropertyType.Rent:
                mappedProperty = new RentalProperty(baseProperty);
                var rentalProperty = mappedProperty as RentalProperty;

                rentalProperty.AvailabilityDate = (DateTime)source.AvailabilityDate;
                rentalProperty.Bond             = (decimal)source.Bond;

                return(rentalProperty);

            case PropertyType.Sale:

                mappedProperty = new SellableProperty(baseProperty);
                var sellableProperty = mappedProperty as SellableProperty;

                sellableProperty.AuctionDate = source.AuctionDate;

                return(sellableProperty);

            case PropertyType.Unknown:
            default:
                throw new ApplicationException(string.Format("The property type '{0}' is not recognized.", Enum.GetName(typeof(PropertyType), type)));
            }
        }