Ejemplo n.º 1
0
        public void Save(PersonWithOthers person)
        {
            if (string.IsNullOrEmpty(person.PreferredName))
            {
                person.PreferredName = person.FirstName;
            }

            if (person.Staff != null)
            {
                _entityService.Save <Staff>(person.Staff);
                person.StaffId = person.Staff.Id;
            }
            else
            {
                if (person.StaffId.HasValue)
                {
                    _personRepository.DeleteStaff(person.StaffId.Value);
                }
                person.StaffId = null;
            }

            if (person.Donor != null)
            {
                _entityService.Save(person.Donor);
                person.DonorId = person.Donor.Id;
            }
            else
            {
                if (person.DonorId.HasValue)
                {
                    _personRepository.DeleteDonor(person.DonorId.Value);
                }
                person.DonorId = null;
            }

            _entityService.Save <PersonExtended>(person);
            if (person.Staff != null)
            {
                MatchStaffWithUser(person.Staff, person.Id);
            }

            if (person.SpouseChanged)
            {
                if (person.SpouseId.HasValue)
                {
                    //find the spouse and set them to be this persons spouse
                    _personRepository.PeopleExtended.Where(extended => extended.Id == person.SpouseId)
                    .Set(extended => extended.SpouseId, person.Id).Update();
                    //note at the moment you could orphan a spouse this way, in the future we could write another update
                    //so to set anyone who has this person as a spouse to null, this would only happen
                    //if you changed someone from the spouse of one person to another though
                }
                else
                {
                    //find the current spouse and make them not spouses anymore
                    _personRepository.PeopleExtended.Where(extended => extended.SpouseId == person.Id)
                    .Set(extended => extended.SpouseId, (Guid?)null).Update();
                }
            }
        }
Ejemplo n.º 2
0
 public Task <ActionResult <PersonWithOthers> > Update([FromBody] PersonWithOthers person)
 {
     return(TryExecute(MyPolicies.peopleEdit,
                       person.Id,
                       () =>
     {
         _personService.Save(person);
         return person;
     }));
 }
Ejemplo n.º 3
0
        public IActionResult UpdateSelf([FromBody] PersonWithOthers person)
        {
            if (User.PersonId() != person.Id)
            {
                throw new UnauthorizedAccessException("You're only allowed to modify your own details ");
            }

            _personService.Save(person);
            return(Json(person));
        }
Ejemplo n.º 4
0
 public LeaveDetails GetCurrentLeaveDetails(PersonWithOthers person)
 {
     return(GetLeaveDetails(person.Id, person.Roles, DateTime.Now.SchoolYear()));
 }