Exemple #1
0
        public Person GetLandlord([FromQuery]string role)
        {
            //var role = "Tenant";
            var person = new Person(){DateOfBirth = DateTime.Today};

            if (role.ToLower() == "landlord")
            {
                var landlordRole = _context.Roles.First(r => r.Name == role);
                var roleAttributes =
                    _context.RoleAttributes.Where(a => a.RoleId == landlordRole.Id && !string.IsNullOrEmpty(a.Attribute));

                foreach (var tenantroleAttribute in roleAttributes)
                {
                    var pa = new PersonAttribute();
                    pa.RoleAttributeId = tenantroleAttribute.Id;
                    pa.RoleAttribute = tenantroleAttribute;
                    if (tenantroleAttribute.ValueType == "date")
                    {
                        pa.DateValue = DateTime.Today;
                    }

                    person.PersonAttributes.Add(pa);
                }

                person.AddressOwnerships = new List<AddressOwnership>
                    {
                        new AddressOwnership {Address = new Address {AddressLine1 = "Line 1", City = "City", PostCode = "Pin"}, OwnedFrom = DateTime.Today, OwnedTo = DateTime.Today}
                    };

            }

            return person;
        }
Exemple #2
0
        public IActionResult Create(Person person)
        {
            if (ModelState.IsValid)
            {
                var roleAttributes =
                    _context.RoleAttributes.Where(
                        a => person.PersonAttributes.Select(p => p.RoleAttributeId).Contains(a.Id));

                var emptyRoleAttributes = roleAttributes.Where(r => string.IsNullOrEmpty(r.Attribute)).Select(a => a.Id);

                var attributesToRemove = person.PersonAttributes.Where(a => emptyRoleAttributes.Contains(a.RoleAttributeId) || (a.StringValue==null && a.DateValue==null && a.FloatValue==null && a.IntValue==null)).ToList();

                attributesToRemove.ForEach(a=>person.PersonAttributes.Remove(a));

                _context.People.Add(person);
                _context.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(person);
        }
Exemple #3
0
        // GET: People/Create
        public IActionResult Create()
        {
            var person = new Person();
            var tenantRole = _context.Roles.First(r => r.Name == "Tenant");
            var tenantroleAttributes = _context.RoleAttributes.Where(a => a.RoleId == tenantRole.Id && !string.IsNullOrEmpty(a.Attribute));

            foreach (var tenantroleAttribute in tenantroleAttributes)
            {
                var pa=new PersonAttribute();
                pa.RoleAttributeId = tenantroleAttribute.Id;
                pa.RoleAttribute = tenantroleAttribute;
                person.PersonAttributes.Add(pa);
                if (tenantroleAttribute.ValueType == "date")
                {
                    pa.DateValue=DateTime.Today;
                }
            }
            person.AddressOccupations = new List<AddressOccupation>
            {
                new AddressOccupation {Address = new Address(),OccupiedFrom = DateTime.Today, OccupiedTo = DateTime.Today}

            };
            return View(person);
        }
Exemple #4
0
 public async Task<IActionResult> Create(Person person)
 {
     if (ModelState.IsValid)
     {
         _context.People.Add(person);
         await _context.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     return View(person);
 }
Exemple #5
0
 public IActionResult Edit(Person person)
 {
     if (ModelState.IsValid)
     {
         _context.Update(person);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(person);
 }