[TestMethod] // [2] Update Lease
        public void PutLeaseUpdateLease()
        {
            //Arrange
            var lCtrl = new LeasesController();

            var newLease = new LeaseModel
            {
                PropertyId = 1,
                TenantId   = 1,
                StartDate  = DateTime.Now,
                Rent       = 2000
            };

            //The result of the PostRequest
            IHttpActionResult result = lCtrl.PostLease(newLease);

            //Cast result as the content result so I can gather information from Content Result
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult = (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            //REsult containts the property I had just created
            result = lCtrl.GetLease(contentResult.Content.LeaseId);

            //GET PropertyModel from Result
            OkNegotiatedContentResult <LeaseModel> propertyResult = (OkNegotiatedContentResult <LeaseModel>)result;

            //Act
            result = lCtrl.PutLease(propertyResult.Content.LeaseId, newLease);

            //Assert
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
        }
Exemple #2
0
        public bool CreateLease(LeaseModel lease, int ownerId, string username)
        {
            var property = this.Entities.Properties.Find(lease.PropertyId);

            if (property != null && property.OwnerId == ownerId && property.Owner.AspNetUser.UserName.Equals(username))
            {
                var leaseDb = new Lease
                {
                    PropertyId                = lease.PropertyId,
                    InitialDeposit            = lease.InitialDeposit,
                    LeaseStatusId             = lease.LeaseStatusId,
                    Duration                  = lease.Duration,
                    EndDate                   = lease.EndDate,
                    InitialDepositDescription = lease.InitialDepositDescription,
                    MonthlyRent               = lease.MonthlyRent,
                    StartDate                 = lease.StartDate,
                    TenantId                  = lease.TenantId
                };

                this.Entities.Leases.Add(leaseDb);
                property.PropertyStatusId = 2;
                foreach (var leaseApplication in property.LeaseApplications)
                {
                    leaseApplication.LeaseApplicationStatusId = 4; // Archived
                }
                this.Entities.SaveChanges();
                return(true);
            }
            return(false);
        }
Exemple #3
0
        private async Task AuthenticateByIP(string ip)
        {
            bool valid = IPAddress.TryParse(ip, out IPAddress address);

            if (!valid)
            {
                return;
            }

            List <Lease> matches = LeaseModel.FindByIP(address);

            if (matches.Count == 0)
            {
                return;
            }

            foreach (Lease match in matches)
            {
                List <User> users = await UserModel.FindByMAC(match.MAC);

                foreach (User user in users)
                {
                    Console.WriteLine($"{match.IP} / {match.MAC} -> {user.Username}");
                    User            = user;
                    IsAuthenticated = true;
                    NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
                }
            }
        }
Exemple #4
0
        public IHttpActionResult PutLease(int id, LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != lease.LeaseId)
            {
                return(BadRequest());
            }

            var dbLease = db.Leases.FirstOrDefault(l => l.User.UserName == User.Identity.Name && l.LeaseId == id);

            dbLease.Update(lease);
            db.Entry(dbLease).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeaseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #5
0
 public bool Save(LeaseModel model)
 {
     using (DataProvider dp = new DataProvider())
     {
         var entity = data.GetLeaById(dp, model.Id);
         if (entity == null)
         {
             model.IsDel      = false;
             model.CreateTime = DateTime.Now;
             dp.PM_Lease.Add(Mapper.Map <PM_Lease>(model));
         }
         else
         {
             entity.LeaseName  = model.LeaseName;
             entity.LeaseType  = model.LeaseType;
             entity.Sort       = model.Sort;
             entity.IsEnabled  = model.IsEnabled;
             entity.UpdateUser = model.UpdateUser;
             entity.UpdateTime = DateTime.Now;
         }
         try
         {
             dp.SaveChanges();
             return(true);
         }
         catch
         {
             throw;
         }
     }
 }
 public void Update(LeaseModel model)
 {
     StartDate     = model.StartDate;
     EndDate       = model.EndDate;
     RentAmount    = model.RentAmount;
     RentFrequency = model.RentFrequency;
 }
Exemple #7
0
        public void PostLeaseCreatesLease()
        {
            //Arrange: Instantiate LeasesController so its methods can be called
            var leaseController = new LeasesController();

            //Act:
            // Create a LeaseModel object populated with test data,
            //  and call PostLease
            var newLease = new LeaseModel
            {
                CreatedDate = new DateTime(2014, 9, 30),
                PropertyId  = 1,
                TenantId    = 1,
                StartDate   = new DateTime(2015, 1, 30),
                Rent        = 800,
                LeaseType   = Constants.RentPeriod.Monthly
            };
            IHttpActionResult result = leaseController.PostLease(newLease);

            //Assert:
            // Verify that the HTTP result is CreatedAtRouteNegotiatedContentResult
            // Verify that the HTTP result body contains a nonzero lease ID
            Assert.IsInstanceOfType
                (result, typeof(CreatedAtRouteNegotiatedContentResult <LeaseModel>));
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            Assert.IsTrue(contentResult.Content.LeaseId != 0);

            // Delete the test lease
            result = leaseController.DeleteLease(contentResult.Content.LeaseId);
        }
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Set up new Lease object,
            //  and populate it with the values from
            //  the input LeaseModel object
            Lease dbLease = new Lease();

            dbLease.Update(lease);

            // Add the new Lease object to the list of Lease objects
            db.Leases.Add(dbLease);

            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception("Unable to add the lease to the database.");
            }

            // Update the LeaseModel object with the new lease ID
            //  that was placed in the Lease object after the changes
            //  were saved to the DB
            lease.LeaseId = dbLease.LeaseId;
            return(CreatedAtRoute("DefaultApi", new { id = dbLease.LeaseId }, lease));
        }
Exemple #9
0
        public void DeletePropertyDeletesProperty()
        {
            //Arrange:
            // Instantiate PropertiesController so its methods can be called
            // Create a new property to be deleted, and get its property ID

            var propertyController = new PropertiesController();

            var property = new PropertyModel
            {
                Name     = "Office Space",
                Address1 = "101 Broadway",
                City     = "San Francisco",
                State    = "CA"
            };
            IHttpActionResult propertyResult = propertyController.PostProperty(property);
            CreatedAtRouteNegotiatedContentResult <PropertyModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <PropertyModel>)propertyResult;

            int propertyIdToDelete = contentResult.Content.PropertyId;

            // Add a lease corresponding to the property
            int createdLeaseId;

            using (var leaseController = new LeasesController())
            {
                var lease = new LeaseModel
                {
                    CreatedDate = new DateTime(2014, 9, 30),
                    PropertyId  = propertyIdToDelete,
                    TenantId    = 1,
                    StartDate   = new DateTime(2015, 1, 30),
                    Rent        = 800,
                    LeaseType   = Constants.RentPeriod.Monthly
                };
                IHttpActionResult leaseResult = leaseController.PostLease(lease);
                CreatedAtRouteNegotiatedContentResult <LeaseModel> leaseContentResult =
                    (CreatedAtRouteNegotiatedContentResult <LeaseModel>)leaseResult;

                createdLeaseId = leaseContentResult.Content.LeaseId;
            }

            //Act: Call DeleteProperty
            propertyResult = propertyController.DeleteProperty(propertyIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted property returns result not found
            Assert.IsInstanceOfType(propertyResult, typeof(OkNegotiatedContentResult <PropertyModel>));

            propertyResult = propertyController.GetProperty(propertyIdToDelete);
            Assert.IsInstanceOfType(propertyResult, typeof(NotFoundResult));

            // Verify that the lease created above was deleted
            using (var leaseController = new LeasesController())
            {
                IHttpActionResult leaseResult = leaseController.GetLease(createdLeaseId);
                Assert.IsInstanceOfType(leaseResult, typeof(NotFoundResult));
            }
        }
Exemple #10
0
        public void DeleteLeaseDeletesLease()
        {
            //Arrange:
            // Instantiate LeasesController so its methods can be called
            // Create a new lease to be deleted, and get its lease ID
            var leaseController = new LeasesController();

            var lease = new LeaseModel
            {
                CreatedDate = new DateTime(2014, 9, 30),
                PropertyId  = 1,
                TenantId    = 1,
                StartDate   = new DateTime(2015, 1, 30),
                Rent        = 800,
                LeaseType   = Constants.RentPeriod.Monthly
            };
            IHttpActionResult result = leaseController.PostLease(lease);
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            int leaseIdToDelete = contentResult.Content.LeaseId;


            //Act: Call DeleteLease
            result = leaseController.DeleteLease(leaseIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted lease returns result not found
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <LeaseModel>));

            result = leaseController.GetLease(leaseIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void DeleteTenantDeletesTenant()
        {
            //Arrange:
            // Instantiate TenantsController so its methods can be called
            // Create a new tenant to be deleted, and get its tenant ID
            var tenantController = new TenantsController();

            var tenant = new TenantModel
            {
                FirstName    = "Testy",
                LastName     = "Testering",
                Telephone    = "555-1212",
                EmailAddress = "*****@*****.**"
            };
            IHttpActionResult result = tenantController.PostTenant(tenant);
            CreatedAtRouteNegotiatedContentResult <TenantModel> contentResult =
                (CreatedAtRouteNegotiatedContentResult <TenantModel>)result;

            int tenantIdToDelete = contentResult.Content.TenantId;

            // Add a lease corresponding to the tenant
            int createdLeaseId;

            using (var leaseController = new LeasesController())
            {
                var lease = new LeaseModel
                {
                    CreatedDate = new DateTime(2014, 9, 30),
                    PropertyId  = 1,
                    TenantId    = tenantIdToDelete,
                    StartDate   = new DateTime(2015, 1, 30),
                    Rent        = 800,
                    LeaseType   = Constants.RentPeriod.Monthly
                };
                IHttpActionResult leaseResult = leaseController.PostLease(lease);
                CreatedAtRouteNegotiatedContentResult <LeaseModel> leaseContentResult =
                    (CreatedAtRouteNegotiatedContentResult <LeaseModel>)leaseResult;

                createdLeaseId = leaseContentResult.Content.LeaseId;
            }

            //Act: Call DeleteTenant
            result = tenantController.DeleteTenant(tenantIdToDelete);

            //Assert:
            // Verify that HTTP result is OK
            // Verify that reading deleted tenant returns result not found
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <TenantModel>));

            result = tenantController.GetTenant(tenantIdToDelete);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            // Verify that the lease created above was deleted
            using (var leaseController = new LeasesController())
            {
                IHttpActionResult leaseResult = leaseController.GetLease(createdLeaseId);
                Assert.IsInstanceOfType(leaseResult, typeof(NotFoundResult));
            }
        }
 public void Update(LeaseModel lease)
 {
     PropertyId = lease.PropertyId;
     TenantId   = lease.TenantId;
     StartDate  = lease.StartDate;
     EndDate    = lease.EndDate;
     Rent       = lease.Rent;
 }
 public void Update(LeaseModel modelLease)
 {
     TenantId      = modelLease.TenantId;
     PropertyId    = modelLease.PropertyId;
     StartDate     = modelLease.StartDate;
     EndDate       = modelLease.EndDate;
     RentAmount    = modelLease.RentAmount;
     RentFrequency = modelLease.RentFrequency;
 }
Exemple #14
0
        public void PutLeaseUpdatesLease()
        {
            int     leaseIdForTest   = 1;
            decimal leaseRentForTest = 987654321;

            Constants.RentPeriod leaseTypeForTest = Constants.RentPeriod.Daily;

            //Arrange: Instantiate LeasesController so its methods can be called
            var leaseController = new LeasesController();

            //Act:
            // Get an existing lease, change it, and
            //  pass it to PutLease

            IHttpActionResult result = leaseController.GetLease(leaseIdForTest);
            OkNegotiatedContentResult <LeaseModel> contentResult =
                (OkNegotiatedContentResult <LeaseModel>)result;
            LeaseModel updatedLease = (LeaseModel)contentResult.Content;

            decimal leaseRentBeforeUpdate = updatedLease.Rent;

            Constants.RentPeriod leaseTypeBeforeUpdate = updatedLease.LeaseType;

            updatedLease.Rent      = leaseRentForTest;
            updatedLease.LeaseType = leaseTypeForTest;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the lease and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = leaseController.GetLease(leaseIdForTest);

            Assert.IsInstanceOfType(result,
                                    typeof(OkNegotiatedContentResult <LeaseModel>));

            OkNegotiatedContentResult <LeaseModel> readContentResult =
                (OkNegotiatedContentResult <LeaseModel>)result;

            updatedLease = (LeaseModel)readContentResult.Content;

            Assert.IsTrue(updatedLease.Rent == leaseRentForTest);
            Assert.IsTrue(updatedLease.LeaseType == leaseTypeForTest);

            updatedLease.Rent      = leaseRentBeforeUpdate;
            updatedLease.LeaseType = leaseTypeBeforeUpdate;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);
        }
Exemple #15
0
 public void Update(LeaseModel model)
 {
     LeaseId       = model.LeaseId;
     TenantId      = model.TenantId;
     PropertyId    = model.PropertyId;
     StartDate     = model.StartDate;
     EndDate       = model.EndDate;
     RentAmount    = model.RentAmount;
     RentFrequency = model.RentFrequency;
 }
Exemple #16
0
        public IHttpActionResult GetLease(int id)
        {
            LeaseModel lease = Mapper.Map <LeaseModel>(db.Leases.Find(id));

            if (lease == null)
            {
                return(NotFound());
            }

            return(Ok(lease));
        }
Exemple #17
0
        public void TestDistinctLeaseClients()
        {
            var distinctLeaseClients = LeaseModel.LeaseDetailsByMAC(TimeSpan.FromDays(7));

            foreach (Lease distinctLeaseClient in distinctLeaseClients)
            {
                Console.WriteLine(distinctLeaseClient.MAC);
            }

            Console.WriteLine(distinctLeaseClients.Count);
        }
Exemple #18
0
 public ActionResult SaveUpdateLease(LeaseModel model)
 {
     try
     {
         return(Json(new { Msg = (new LeaseModel().SaveUpdateLease(model)) }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { Msg = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbLease = new Lease(lease);

            db.Leases.Add(dbLease);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = dbLease.LeaseId }, Mapper.Map <LeaseModel>(lease)));
        }
Exemple #20
0
        public void Update(LeaseModel modelLease)
        {
            // If adding new lease, set created date
            if (modelLease.LeaseId == 0)
            {
                CreatedDate = DateTime.Now;
            }

            // Copy values from input object to Lease lease
            PropertyId = modelLease.PropertyId;
            TenantId   = modelLease.TenantId;
            StartDate  = modelLease.StartDate;
            EndDate    = modelLease.EndDate;
            Rent       = modelLease.Rent;
            LeaseType  = modelLease.LeaseType;
        }
Exemple #21
0
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbLease = new Lease(lease);

            dbLease.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            db.Leases.Add(dbLease);
            db.SaveChanges();

            lease.LeaseId = dbLease.LeaseId;

            return(CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease));
        }
Exemple #22
0
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newLease = new Lease();

            newLease.Update(lease);

            db.Leases.Add(newLease);
            db.SaveChanges();

            lease.LeaseId = newLease.LeaseId;

            return(CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease));
        }
        public IHttpActionResult PutLease(int id, LeaseModel lease)
        {
            // Validate the request
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != lease.LeaseId)
            {
                return(BadRequest());
            }

            if (!LeaseExists(id))
            {
                return(BadRequest());
            }

            // Get the lease record corresponding to the lease ID, then
            //   update its properties to the values in the input LeaseModel object,
            //   and then set indicator that the record has been modified
            var dbLease = db.Leases.Find(id);

            dbLease.Update(lease);
            db.Entry(dbLease).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeaseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw new Exception("Unable to update the lease in the database.");
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #24
0
 public ActionResult Save(LeaseModel lea)
 {
     try
     {
         if (!lea.Id.HasValue)
         {
             lea.CreateUser = CurrentUser.Id;
         }
         else
         {
             lea.UpdateUser = CurrentUser.Id;
         }
         return(Json(new JsonMessage(business.Save(lea))));
     }
     catch (Exception e)
     {
         return(Json(new JsonMessage(false, e.Message)));
     }
 }
Exemple #25
0
        public IHttpActionResult PutLease(int id, LeaseModel modelLease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != modelLease.LeaseId)
            {
                return(BadRequest());
            }

            // 1. Grab the entry from the database
            var dbLease = db.Leases.Find(id);

            // 2. Update the entryfetched from the database
            dbLease.Update(modelLease);

            // 3. Mark entry as modified
            db.Entry(dbLease).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LeaseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        [TestMethod] // [4] Delete Lease
        public void DeleteLeaseDeleteLease()
        {
            //Arrange
            var lCtrl = new LeasesController();

            var newLease = new LeaseModel
            {
                PropertyId = 1,
                TenantId   = 1,
                StartDate  = DateTime.Now,
                Rent       = 2000
            };

            //Add 'new property to database using post'
            //Save returned value as RESULT
            IHttpActionResult result = lCtrl.PostLease(newLease);

            //Cast result as Content Result so I can gathere information from the content result
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult = (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            //Result contains the property I had just created
            result = lCtrl.GetLease(contentResult.Content.PropertyId);

            //Get PropertyModel from result
            OkNegotiatedContentResult <LeaseModel> leaseResult = (OkNegotiatedContentResult <LeaseModel>)result;

            //Act
            result = lCtrl.DeleteLease(contentResult.Content.LeaseId);

            //Assert

            //If action returns not found
            Assert.IsNotInstanceOfType(result, typeof(NotFoundResult));

            //If action retruns OK()
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <LeaseModel>));
        }
        [TestMethod]// [3] Create Lease
        public void POSTLeaseCreateLease()
        {
            //Arrange
            var lCtrl = new LeasesController();

            var newLease = new LeaseModel
            {
                PropertyId = 1,
                TenantId   = 1,
                StartDate  = DateTime.Now,
                Rent       = 2000
            };

            //Result of the Post Request
            IHttpActionResult result = lCtrl.PostLease(newLease);

            //Assert
            Assert.IsInstanceOfType(result, typeof(CreatedAtRouteNegotiatedContentResult <LeaseModel>));

            //Cast
            CreatedAtRouteNegotiatedContentResult <LeaseModel> contentResult = (CreatedAtRouteNegotiatedContentResult <LeaseModel>)result;

            Assert.IsTrue(contentResult.Content.LeaseId != 0);
        }
Exemple #28
0
 public static LeaseViewModel ToViewModel(this LeaseModel model)
 {
     return(Mapper.Map <LeaseModel, LeaseViewModel>(model));
 }
 public void Update(LeaseModel lease)
 {
     StartDate = lease.StartDate;
     EndDate   = lease.EndDate;
     Rent      = lease.Rent;
 }
 public bool CreateSubscription(LeaseModel leaseModel)
 {
     // Save DTO information in database using dapper and response with success or error
     return(true);
 }