Example #1
0
        public ActionResult Edit(int id)
        {
            var tenant    = _tenantRepository.Get(id);
            var viewModel = new TenantFormViewModel(tenant);

            return(View(viewModel));
        }
        public ActionResult Form(TenantFormViewModel Form)
        {
            if (!ModelState.IsValid)
            {
                return(View("Form", Form));
            }

            var tenant = new Tenant
            {
                shopName  = Form.shopName,
                brandName = Form.brandName,
                Address   = Form.Address,
                mobileNo  = Form.mobileNo,
                panNo     = Form.panNo
            };



            _context.Tenant.Add(tenant);

            _context.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
Example #3
0
        public ActionResult Form()
        {
            var viewModel = new TenantFormViewModel
            {
                Units   = _context.Unit.ToList(),
                Tenants = _context.Tenant.ToList()
            };

            return(View(viewModel));
        }
Example #4
0
        public ActionResult Create(TenantFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tenant = Mapper.Map <TenantFormViewModel, Tenant>(viewModel);

            _unitOfWork.Tenants.Add(tenant);
            _unitOfWork.Complete();

            return(RedirectToAction("Index"));
        }
Example #5
0
        public async Task <IHttpActionResult> Post(TenantFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lease = model.Lease;

            foreach (var file in model.Files)
            {
                lease.LeaseFiles.Add(new LeaseFile
                {
                    Path = file.Path
                });
            }
            _db.Leases.Add(lease);

            await _db.SaveChangesAsync();

            var tenant = model.Tenants[0];

            tenant.LeaseId = lease.Id;
            tenant.PropertyTenantMaps.Add(new PropertyTenantMap
            {
                PropertyId = model.Property.Id
            });

            for (var i = 1; i < model.Tenants.Count; i++)
            {
                var principalTenant = model.Tenants[i];

                principalTenant.LeaseId = lease.Id;
                principalTenant.PropertyTenantMaps.Add(new PropertyTenantMap
                {
                    PropertyId = model.Property.Id
                });

                tenant.PrincipalTenants.Add(principalTenant);
            }

            _db.Tenants.Add(tenant);

            await _db.SaveChangesAsync();

            return(Ok());
        }
Example #6
0
        public ActionResult Form(TenantFormViewModel Form)
        {
            if (!ModelState.IsValid)
            {
                return(View("Form", Form));
            }

            var tenant = new Tenant
            {
                brandName = Form.brandName,
                Address   = Form.Address,
                mobileNo  = Form.mobileNo,
                panNo     = Form.panNo
            };


            var unit = new Unit
            {
                Size  = Form.Size,
                Floor = Form.Floor
            };
            var shopNo   = _context.Unit.Single(s => s.Id == Form.Unit);     //ID FOR DROP DOWN LIST
            var shopName = _context.Tenant.Single(s => s.Id == Form.Tenant); // ID FOR TENANT SHOPNAME
            var rent     = new Rent
            {
                Amount    = Form.Amount,
                startDate = DateTime.Parse(string.Format("{0}", Form.startDate)),
                endDate   = DateTime.Parse(string.Format("{0}", Form.endDate)),

                Unit   = shopNo,
                Tenant = shopName
            };


            //TO ADD A DATA TO THE DATABASE
            _context.Tenant.Add(tenant);
            _context.Unit.Add(unit);
            _context.Rent.Add(rent);



            _context.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Form(TenantFormViewModel Form)
        {
            if (!ModelState.IsValid)
            {
                return(View("Form", Form));
            }



            var tenant = new Tenant
            {
                shopName  = Form.shopName,
                brandName = Form.brandName,
                Address   = Form.Address,
                mobileNo  = Form.mobileNo,
                panNo     = Form.panNo
            };

            var unit = new Unit
            {
                Size   = Form.Size,
                Floor  = Form.Floor,
                shopNo = Form.shopNo
            };



            var rent = new Rent
            {
                Amount    = Form.Amount,
                startDate = DateTime.Parse(string.Format("{0}", Form.startDate)),
                endDate   = DateTime.Parse(string.Format("{0}", Form.endDate)),
            };

            _context.Tenant.Add(tenant);
            _context.Unit.Add(unit);
            _context.Rent.Add(rent);



            _context.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }
Example #8
0
        public ActionResult Delete(TenantFormViewModel viewModel)
        {
            if (!ViewData.ModelState.IsValid)
            {
                return(this.RedirectToAction(c => c.Edit(viewModel.Id)));
            }

            try {
                var tenant = _tenantRepository.Get(viewModel.Id);
                _tenantRepository.Delete(tenant);
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully deleted tenant '{0}'", tenant.Name);
            }
            catch (Exception ex) {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred deleting the tenant: {0}", ex.Message);
                return(this.RedirectToAction(c => c.Edit(viewModel.Id)));
            }

            return(this.RedirectToAction(c => c.Index(null)));
        }
Example #9
0
        public ActionResult Edit(TenantFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var tenant = _unitOfWork.Tenants.GetTenant(viewModel.Id);

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

            Mapper.Map(viewModel, tenant);

            _unitOfWork.Complete();

            return(RedirectToAction("Index"));
        }
Example #10
0
        public ActionResult Create(TenantFormViewModel viewModel)
        {
            if (!ViewData.ModelState.IsValid)
            {
                TempData.SafeAdd(viewModel);
                return(this.RedirectToAction(c => c.Create()));
            }

            try {
                var tenant = new Tenant {
                    Name = viewModel.Name, Domain = viewModel.Domain, ConnectionString = viewModel.ConnectionString
                };
                _tenantRepository.SaveOrUpdate(tenant);
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("Successfully created tenant '{0}'", tenant.Name);
            }
            catch (Exception ex) {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = string.Format("An error occurred creating the tenant: {0}", ex.Message);
                return(this.RedirectToAction(c => c.Create()));
            }

            return(this.RedirectToAction(c => c.Index(null)));
        }
Example #11
0
        public async Task <IHttpActionResult> GetDetails(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var tenant = await _db.Tenants.Include(a => a.PropertyTenantMaps).Include(a => a.PropertyTenantMaps.Select(s => s.Property)).Include(a => a.PrincipalTenants).Include(a => a.Lease).Include(a => a.Lease.LeaseFiles).FirstOrDefaultAsync(f => f.Id == id);

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

            var model = new TenantFormViewModel();

            model.Property = tenant.PropertyTenantMaps.FirstOrDefault(f => f.TenantId == id)?.Property;
            model.Tenants.Add(tenant);
            model.Tenants.AddRange(tenant.PrincipalTenants);
            model.Lease = tenant.Lease;
            model.Files = tenant.Lease.LeaseFiles.ToList();

            return(Ok(model));
        }
Example #12
0
        public async Task <IHttpActionResult> Put(TenantFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lease = await _db.Leases.Include(i => i.LeaseFiles).FirstOrDefaultAsync(f => f.Id == model.Lease.Id);

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

            lease.DelinquentAfter    = model.Lease.DelinquentAfter;
            lease.Deposit            = model.Lease.Deposit;
            lease.EndDate            = model.Lease.EndDate;
            lease.LeaseTypeId        = model.Lease.LeaseTypeId;
            lease.MoveInDate         = model.Lease.MoveInDate;
            lease.Notes              = model.Lease.Notes;
            lease.PaymentFrequencyId = model.Lease.PaymentFrequencyId;
            lease.PaymentTypeId      = model.Lease.PaymentTypeId;
            lease.PetsFlag           = model.Lease.PetsFlag;
            lease.Rent        = model.Lease.Rent;
            lease.SmokingFlag = model.Lease.SmokingFlag;
            lease.StartDate   = model.Lease.StartDate;

            foreach (var file in model.Files.Where(w => w.Id == 0))
            {
                lease.LeaseFiles.Add(new LeaseFile
                {
                    Path = file.Path
                });
            }

            _db.Leases.Attach(lease);
            _db.Entry(lease).State = EntityState.Modified;

            await _db.SaveChangesAsync();

            var id     = model.Tenants[0].Id;
            var tenant = await _db.Tenants.Include(i => i.PropertyTenantMaps).Include(i => i.PrincipalTenants).FirstOrDefaultAsync(f => f.Id == id);

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

            if (tenant.PropertyTenantMaps.Any(a => a.PropertyId != model.Property.Id))
            {
                tenant.PropertyTenantMaps.Remove(tenant.PropertyTenantMaps.FirstOrDefault(f => f.TenantId == model.Tenants[0].Id));
                tenant.PropertyTenantMaps.Add(new PropertyTenantMap
                {
                    PropertyId = model.Property.Id
                });
            }
            tenant.Company   = model.Tenants[0].Company;
            tenant.FirstName = model.Tenants[0].FirstName;
            tenant.LastName  = model.Tenants[0].LastName;
            tenant.CellPhone = model.Tenants[0].CellPhone;
            tenant.Email     = model.Tenants[0].Email;
            tenant.HomePhone = model.Tenants[0].HomePhone;
            tenant.DOB       = model.Tenants[0].DOB;

            for (var i = 1; i < model.Tenants.Count; i++)
            {
                var principalTenant = model.Tenants[i];

                if (principalTenant.Id == 0)
                {
                    principalTenant.LeaseId = lease.Id;
                    principalTenant.PropertyTenantMaps.Add(new PropertyTenantMap
                    {
                        PropertyId = model.Property.Id
                    });
                    principalTenant.PrincipalTenantId = id;

                    tenant.PrincipalTenants.Add(principalTenant);
                }
                else
                {
                    principalTenant = tenant.PrincipalTenants.FirstOrDefault(f => f.Id == principalTenant.Id);

                    principalTenant.Company   = model.Tenants[i].Company;
                    principalTenant.FirstName = model.Tenants[i].FirstName;
                    principalTenant.LastName  = model.Tenants[i].LastName;
                    principalTenant.CellPhone = model.Tenants[i].CellPhone;
                    principalTenant.Email     = model.Tenants[i].Email;
                    principalTenant.HomePhone = model.Tenants[i].HomePhone;
                    principalTenant.DOB       = model.Tenants[i].DOB;
                }
            }

            _db.Tenants.Attach(tenant);
            _db.Entry(tenant).State = EntityState.Modified;

            await _db.SaveChangesAsync();

            return(Ok());
        }