/// <summary> /// Create data in database /// </summary> /// <param name="userInfo">UserInfo</param> /// <returns>insert data</returns> public UserInfo Create(UserInfo userInfo) { if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId)) return null; var row = new UserInfoRow(); UserInfoTransformer.ToRow(userInfo, row); _dbContext.UserInfo.Add(row); _dbContext.SaveChanges(); return UserInfoTransformer.ToBean(row); }
internal static UserInfo ToBean(UserInfoRow row) { if (row == null) return null; var bean = new UserInfo(); bean.UserId = row.UserId; bean.Unit = (TUnitType)row.Unit; bean.Height = row.Height; bean.Weight = row.Weight; bean.Sex = (TSexType)row.Sex; bean.ZipCode = row.ZipCode; bean.CountryId = row.CountryId; if (string.IsNullOrWhiteSpace(row.TimeZoneName)) bean.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id); else bean.TimeZoneName = row.TimeZoneName; return bean; }
public static void ToRow(UserInfo bean, UserInfoRow row) { if (bean == null) return; row.UserId = bean.UserId; row.Unit = (int)bean.Unit; row.Height = bean.Height; row.Weight = bean.Weight; row.Sex = (int)bean.Sex; row.ZipCode = bean.ZipCode; row.CountryId = bean.CountryId; if (string.IsNullOrWhiteSpace(bean.TimeZoneName)) { if(string.IsNullOrWhiteSpace(row.TimeZoneName)) // only update if not present row.TimeZoneName = TimeZoneMapper.GetOlsonTimeZoneName(TimeZoneInfo.Local.Id); } else row.TimeZoneName = bean.TimeZoneName; }