public static BaseActionResult CreateUser(User obj4create) { string msg; if (obj4create == null) { msg = string.Format(Intern4jobResources.MSG_CREATE_SUCCESS, Intern4jobResources.STR_USER) + string.Format(Intern4jobResources.STR_FAIL_RESAON, Intern4jobResources.MSG_OBJECT_IS_NULL); return new BaseActionResult(false, msg); } try { using (var context = new Intern4jobEntities()) { var repository = new UserRepository(context); string newId = Guid.NewGuid().ToString(); obj4create.Id = newId; repository.Create(obj4create); context.SaveChanges(); msg = string.Format(Intern4jobResources.MSG_CREATE_SUCCESS, obj4create.Name); return new BaseActionResult(true, msg); } } catch (Exception e) { msg = string.Format(Intern4jobResources.MSG_CREATE_FAIL, obj4create.Name) + string.Format(Intern4jobResources.STR_FAIL_RESAON, ExceptionHelper.GetInnerExceptionInfo(e)); return new BaseActionResult(false, msg); } }
public static BaseActionResult DeleteUser(User obj4delete) { using (var context = new Intern4jobEntities()) { string msg; var repository = new UserRepository(context); if (obj4delete == null) { msg = string.Format(Intern4jobResources.MSG_DELETE_SUCCESS, Intern4jobResources.STR_USER) + string.Format(Intern4jobResources.STR_FAIL_RESAON, Intern4jobResources.MSG_OBJECT_IS_NULL); return new BaseActionResult(false, msg); } repository.Delete(obj4delete); context.SaveChanges(); msg = string.Format(Intern4jobResources.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; return true; }