//updates data of selected person public void UpdateOccupant(int id, int appartmentId, string first, string last, string middle, Gender gender, DateTime birthDate, bool owner) { Occupant occupant = context.Occupants.Where(x => x.OccupantId == id).FirstOrDefault <Occupant>(); occupant.FirstName = first; occupant.LastName = last; occupant.MiddleName = middle; occupant.Gender = gender; occupant.BirthDate = birthDate; occupant.Owner = owner; OccupantCheck.Require(occupant.FirstName); OccupantCheck.Require(occupant.LastName); context.Entry(occupant).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
//adds newly created person to selected appartment //and to repository public int AddNewOccupant(int appartmentId, string first, string last, string middle, Gender gender, DateTime birthDate, bool owner) { Occupant occupant = new Occupant(); occupant.AppartmentId = appartmentId; occupant.FirstName = first; occupant.LastName = last; occupant.MiddleName = middle; occupant.Gender = gender; occupant.BirthDate = birthDate; occupant.Owner = owner; OccupantCheck.Require(occupant.FirstName); OccupantCheck.Require(occupant.LastName); context.Occupants.Add(occupant); context.SaveChanges(); return(occupant.OccupantId); }