コード例 #1
0
ファイル: LandlordController.cs プロジェクト: eshivakant/TVS
        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;
        }
コード例 #2
0
ファイル: PeopleController.cs プロジェクト: eshivakant/TVS
        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);
        }
コード例 #3
0
ファイル: PeopleController.cs プロジェクト: eshivakant/TVS
        // 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);
        }
コード例 #4
0
ファイル: ReviewsController.cs プロジェクト: eshivakant/TVS
 public async Task<IActionResult> Create(Person person)
 {
     if (ModelState.IsValid)
     {
         _context.People.Add(person);
         await _context.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     return View(person);
 }
コード例 #5
0
ファイル: PeopleController.cs プロジェクト: eshivakant/TVS
 public IActionResult Edit(Person person)
 {
     if (ModelState.IsValid)
     {
         _context.Update(person);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(person);
 }