public IHttpActionResult PutResident(long id, ResidentContract resident)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != resident.PersonalCode)
            {
                return(BadRequest());
            }

            db.Entry(resident.ToInternal()).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResidentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostResident(ResidentContract resident)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Resident temp = resident.ToInternal();

            db.RoomSet.Attach(temp.Room);
            db.DormitorySet.Attach(temp.Dormitory);
            db.ResidentSet.Add(temp);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ResidentExists(resident.PersonalCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = resident.PersonalCode }, resident));
        }