/// <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.Insert(row); return(UserInfoTransformer.ToBean(row)); }
/// <summary> /// Get data in database /// </summary> /// <param name="key">Primary Key</param> /// <returns>read data</returns> public UserInfo Get(UserInfoKey key) { if (key == null || string.IsNullOrWhiteSpace(key.UserId)) { return(null); } var row = _dbContext.UserInfo.Where(m => m.UserId == key.UserId).FirstOrDefault(); if (row != null) { return(UserInfoTransformer.ToBean(row)); } return(null); }
/// <summary> /// Find data in database /// </summary> /// <returns></returns> public List <UserInfo> Find(UserInfoCriteria userInfoCriteria = null) { List <UserInfo> resultList = null; TableQuery <UserInfoRow> rowList = _dbContext.Table <UserInfoRow>(); CriteriaTransformer.CompleteQuery(ref rowList, userInfoCriteria); if (rowList != null && rowList.Count() > 0) { resultList = new List <UserInfo>(); foreach (var userInfoRow in rowList) { resultList.Add(UserInfoTransformer.ToBean(userInfoRow)); } } return(resultList); }
/// <summary> /// Update data in database /// </summary> /// <param name="userInfo">data</param> /// <returns>updated data</returns> public UserInfo Update(UserInfo userInfo) { if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId)) { return(null); } var row = _dbContext.UserInfo.Where(m => m.UserId == userInfo.UserId).FirstOrDefault(); if (row == null) { // No data in database return(Create(userInfo)); } else { //Modify Data in database UserInfoTransformer.ToRow(userInfo, row); _dbContext.SaveChanges(); return(UserInfoTransformer.ToBean(row)); } }
/// <summary> /// Update data in database /// </summary> /// <param name="userInfo">data</param> /// <returns>updated data</returns> public UserInfo Update(UserInfo userInfo) { if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.UserId)) { return(null); } var row = _dbContext.Table <UserInfoRow>().Where(m => m.UserId == userInfo.UserId).FirstOrDefault(); if (row == null) { // No data in database return(Create(userInfo)); } else { //Modify Data in database UserInfoTransformer.ToRow(userInfo, row); _dbContext.Delete(row); //Update don't work... need delete and insert _dbContext.Insert(row); return(UserInfoTransformer.ToBean(row)); } }