public static BaseActionResult CreateUser(User obj4create) { string msg; if (obj4create == null) { msg = string.Format(XiaoluResources.MSG_CREATE_SUCCESS, XiaoluResources.STR_USER) + string.Format(XiaoluResources.STR_FAIL_RESAON, XiaoluResources.MSG_OBJECT_IS_NULL); return new BaseActionResult(false, msg); } try { using (var context = new XiaoluEntities()) { var repository = new UserRepository(context); string newId = Guid.NewGuid().ToString(); obj4create.Id = newId; repository.Create(obj4create); context.SaveChanges(); msg = string.Format(XiaoluResources.MSG_CREATE_SUCCESS, obj4create.Name); return new BaseActionResult(true, msg); } } catch (Exception e) { msg = string.Format(XiaoluResources.MSG_CREATE_FAIL, obj4create.Name) + string.Format(XiaoluResources.STR_FAIL_RESAON, ExceptionHelper.GetInnerExceptionInfo(e)); return new BaseActionResult(false, msg); } }
public UserApiModel(User obj) { Id = obj.Id; Gender = obj.Gender ? "1" : "0"; Name = obj.Name; Password = obj.Password; Description = obj.Description; Birthday = obj.Birthday.Value.ToString("yyyy-mm-dd"); Level = obj.Level.ToString(); Mobile = obj.Mobile; WeixinId = obj.WeixinId; }
public static BaseActionResult DeleteUser(User obj4delete) { using (var context = new XiaoluEntities()) { string msg; var repository = new UserRepository(context); if (obj4delete == null) { msg = string.Format(XiaoluResources.MSG_DELETE_SUCCESS, XiaoluResources.STR_USER) + string.Format(XiaoluResources.STR_FAIL_RESAON, XiaoluResources.MSG_OBJECT_IS_NULL); return new BaseActionResult(false, msg); } repository.Delete(obj4delete); context.SaveChanges(); msg = string.Format(XiaoluResources.MSG_UPDATE_SUCCESS, obj4delete.Name); return new BaseActionResult(true, msg); } }
private static dynamic _orderByKey(User obj, UserQuery query) { if (string.IsNullOrEmpty(query.OrderByKey)) return obj.Id; return obj.GetType().GetProperty(query.OrderByKey).GetValue(obj); }
public static bool _isMatch(User obj, UserQuery query) { if (!string.IsNullOrEmpty(query.IdEqual) && !string.Equals(obj.Id, query.IdEqual)) return false; if (!string.IsNullOrEmpty(query.IdNotEqual) && string.Equals(obj.Id, query.IdNotEqual)) return false; if (!string.IsNullOrEmpty(query.NameEqual) && !string.Equals(obj.Name, query.NameEqual)) return false; if (!string.IsNullOrEmpty(query.NameNotEqual) && string.Equals(obj.Name, query.NameNotEqual)) return false; if (!string.IsNullOrEmpty(query.NameLike) && !obj.Name.Contains(query.NameLike)) return false; if (!string.IsNullOrEmpty(query.StatusEqual) && !string.Equals(obj.Status, query.StatusEqual)) return false; if (!string.IsNullOrEmpty(query.StatusNotEqual) && string.Equals(obj.Status, query.StatusNotEqual)) return false; if ((query.StatusIn != null) && (query.StatusIn.Select(item => string.Equals(item, obj.Status)) == null)) return false; if ((query.StatusNotIn != null) && (query.StatusNotIn.Select(item => string.Equals(item, obj.Status)) != null)) return false; if (!string.IsNullOrEmpty(query.MobileEqual) && !string.Equals(obj.Mobile, query.MobileEqual)) return false; return true; }
public User ToDto() { string errors = ValidateInputs(); if (!string.IsNullOrEmpty(errors)) { throw new Exception(errors); } User newObj = new User() { Id = Id, Name = Name, Password = Password, Description = Description, Birthday = DateTime.Parse(Birthday), Level = Int32.Parse(Level), Gender = Gender.Equals("1"), Mobile = Mobile, WeixinId = WeixinId }; return newObj; }