コード例 #1
0
        //Delete
        public void DeleteTenant(int tenantId)
        {
            var db = new TenantContext();
            var p  = db.Tenants.SingleOrDefault(t => t.Id == tenantId);

            if (p != null)
            {
                db.Tenants.Remove(p);
                db.SaveChanges();
            }
            else
            {
                throw new ApplicationException("Can not find the tenant");
            }
        }
コード例 #2
0
        //Insert
        public void CreateTenant(string fullname,
                                 string rentalPropertyAddress,
                                 DateTime moveInDate,
                                 DateTime leaseEndDate,
                                 decimal monthlyPayment)
        {
            var db = new TenantContext();

            db.Tenants.Add(
                new Tenant
            {
                FullName = fullname,
                RentalPropertyAddress = rentalPropertyAddress,
                MoveInDate            = moveInDate,
                LeaseEndDate          = leaseEndDate,
                MonthlyPayment        = monthlyPayment
            });
            db.SaveChanges();
        }
コード例 #3
0
        //Edit
        public void EditTenant(int id, string fullname,
                               string rentalPropertyAddress,
                               DateTime moveInDate,
                               DateTime leaseEndDate,
                               decimal monthlyPayment)
        {
            var db = new TenantContext();
            var p  = db.Tenants.SingleOrDefault(t => t.Id == id);

            if (p != null)
            {
                p.FullName = fullname;
                p.RentalPropertyAddress = rentalPropertyAddress;
                p.MoveInDate            = moveInDate;
                p.LeaseEndDate          = leaseEndDate;
                p.MonthlyPayment        = monthlyPayment;
                db.SaveChanges();
            }
            else
            {
                throw new ApplicationException("Can not find the tenant");
            }
        }