public static VisitContract ToContract(this VisitInternal entity) { if (entity == null) { return(null); } var visit = new VisitContract { ID = entity.ID, VisitRegDateTime = entity.VisitRegDateTime, IsOver = entity.IsOver, VisitEndDateTime = entity.VisitEndDateTime, ResidentId = entity.Resident.PersonalCode, GuardId = entity.Guard.PersonalCode, DormitoryId = entity.Dormitory.ID, GuestId = entity.Guest.PersonalCode, IsConfirmed = entity.IsConfirmed }; return(visit); }
public static VisitInternal ToInternal(this VisitContract entity) { if (entity == null) { return(null); } ResidentInternal visitResident = new ResidentInternal(); GuardInternal visitGuard = new GuardInternal(); DormitoryInternal visitDormitory = new DormitoryInternal(); GuestInternal visitGuest = new GuestInternal(); using (MainDbModelContainer1 db = new MainDbModelContainer1()) { visitResident = db.ResidentSet.Find(entity.ResidentId); visitGuard = db.GuardSet.Find(entity.GuardId); visitDormitory = db.DormitorySet.Find(entity.DormitoryId); visitGuest = db.GuestSet.Find(entity.GuestId); } var visit = new VisitInternal { ID = entity.ID, VisitRegDateTime = entity.VisitRegDateTime, IsOver = entity.IsOver, VisitEndDateTime = entity.VisitEndDateTime, ResidentPersonalCode = visitResident.PersonalCode, GuardPersonalCode = visitGuard.PersonalCode, DormitoryID = visitDormitory.ID, Guest_PersonalCode = visitGuest.PersonalCode, IsConfirmed = entity.IsConfirmed, Resident = visitResident, Guard = visitGuard, Dormitory = visitDormitory, Guest = visitGuest }; return(visit); }