/// <summary> /// Maps from web to db Model /// </summary> /// <param name="input">List of AddressInformation Web Model</param> /// <param name="refType">OLEAddressInformationRefTypeEnum enum value</param> /// <param name="dbModelList">List of AddressInformation db Model</param> /// <returns>Updated List of AddressInformation db Model</returns> public static List<db.AddressInformation> ToDbModel(this List<AddressInformation> input, OLEAddressInformationRefTypeEnum refType, List<db.AddressInformation> dbModelList) { foreach (var dbItem in new List<db.AddressInformation>(dbModelList)) { if (dbItem.AddressInformationRefType != 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 from web to db Model /// </summary> /// <param name="input">AddressInformation Web Model</param> /// <param name="refType">OLEAddressInformationRefTypeEnum enum value</param> /// <param name="dbModelList">List of AddressInformation db Model</param> /// <returns>Updated List of AddressInformation db Model</returns> public static List<db.AddressInformation> ToDbModel(this AddressInformation input, OLEAddressInformationRefTypeEnum refType, List<db.AddressInformation> dbModelList) { List<AddressInformation> input2 = new List<AddressInformation>(); input2.Add(input); return input2.ToDbModel(refType, dbModelList); }
/// <summary> /// Maps from web to db Model /// </summary> /// <param name="input">List of AddressInformation Web Model</param> /// <param name="refType">OLEAddressInformationRefTypeEnum enum value</param> /// <returns>NEW AddressInformation db Model</returns> public static db.AddressInformation ToDbModel(this AddressInformation input, OLEAddressInformationRefTypeEnum refType) { if (input == null) { return null; } return new db.AddressInformation { City = input.City, Country = input.Country, PostalCode = input.PostalCode, StreetAddress = input.StreetAddress, AddressInformationRefType = refType }; }