/// <summary> /// Maps object from web to db model /// </summary> /// <param name="input">List of type OLEChildDate web</param> /// <param name="refType">OLEChildDataRefTypeEnum value</param> /// <param name="dbModelList">List of type OLEChildDate db</param> /// <returns>List of type OLEChildDate db model</returns> public static List<db.OLEChildData> ToDbModel(this List<OLEChildData> input, OLEChildDataRefTypeEnum refType, List<db.OLEChildData> dbModelList) { foreach (var dbItem in new List<db.OLEChildData>(dbModelList)) { if (dbItem.OLEChildDataRefType != refType) { continue; } // clean db list from unsued items var item = input.Where(o => o.Id == dbItem.Id).FirstOrDefault(); if (item == null) { dbModelList.Remove(dbItem); } } if (input == null) { return dbModelList; } foreach (var item in input) { if (item.Id == 0) { dbModelList.Add(item.ToDbModel(refType)); } else { item.ToDbModel(dbModelList.Where(o => o.Id == item.Id).FirstOrDefault()); } } return dbModelList; }
/// <summary> /// Maps object from web to db model /// </summary> /// <param name="input">OLEChildDate web</param> /// <param name="refType">OLEChildDataRefTypeEnum value</param> /// <returns>OLEChildDate db</returns> public static db.OLEChildData ToDbModel(this OLEChildData input, OLEChildDataRefTypeEnum refType) { return new db.OLEChildData { Birthday = input.Birthday, CurrentCitizenship = input.CurrentCitizenship, Gender = input.Gender.ToDbModel(), MigrationIntentions = input.MigrationIntentions.ToDbModel(), PersonCode = input.PersonCode, PersonNameFirstName = input.PersonName.FirstName, PersonNameLastName = input.PersonName.LastName, OLEChildDataRefType = refType }; }