private static ActionContext CreateContext() { IActionContext ctx = ActiveRecordRegistration.GetContext(typeof(T).FullName); ctx.CombineMessageErrors = true; return(ctx as ActionContext); }
/// <summary> /// Creates a new instance of this DomainModelActiveRecord and /// initializes it so that all of its necessary components are configured. /// Service, Repository, Settings, Validator etc. /// </summary> /// <returns></returns> public static T New() { T model = new T(); ActiveRecordRegistration.InitModel <TId, T>(model, model.ModelName); return(model); }
/// <summary> /// Saves this instance. /// </summary> /// <returns></returns> public static BoolMessage Save(T entity) { ActionContext ctx = new ActionContext(entity, true); IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); return(service.Save(ctx)); }
/// <summary> /// Delete the model associated with the id. /// </summary> /// <param name="id"></param> /// <returns></returns> public static BoolMessage Delete(int id) { IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); ActionContext context = CreateContext(); context.Id = id; return(service.Delete(context)); }
/// <summary> /// Saves this instance. /// </summary> /// <returns></returns> public static BoolMessage Save(T entity) { ActionContext ctx = CreateContext(); ctx.CombineMessageErrors = true; ctx.Item = entity; IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); return(service.Save(ctx)); }
/// <summary> /// Retrieve all instances of model. /// </summary> /// <returns></returns> public static BoolMessageItem <IList <T> > GetAll() { IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); BoolMessageItem <IList <T> > result = service.GetAll(CreateContext()); foreach (T item in result.Item) { ActiveRecordRegistration.InitModel <T>(item, service); } return(result); }
/// <summary> /// Retrieve the model associated with the id. /// </summary> /// <param name="id"></param> /// <returns></returns> public static BoolMessageItem <T> Get(int id) { IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); ActionContext context = CreateContext(); context.Id = id; BoolMessageItem <T> result = service.Get(context); ActiveRecordRegistration.InitModel <T>(result.Item, service); return(result); }
private object InvokeAction(EntityServiceContext ctx, string methodName) { // Create the appropriate type of actioncontext for the specific entity being managed. // And then set it's errors and messages to the calling context so the errors / messages // can be available to the caller. IActionContext actionContext = ActiveRecordRegistration.GetContext(ctx.EntityName); actionContext.CombineMessageErrors = true; actionContext.Item = ctx.Item; actionContext.Id = ctx.Id; actionContext.Errors = ctx.Errors; actionContext.Messages = ctx.Messages; object service = EntityRegistration.GetService(ctx.EntityName); object result = ReflectionUtils.InvokeMethod(service, methodName, new object[] { actionContext }); return(result); }
/// <summary> /// Retrieve the model associated with the id. /// </summary> /// <param name="id"></param> /// <returns></returns> public static BoolMessageItem <T> Get(int id) { IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); return(service.Get(new ActionContext(id, true))); }
/// <summary> /// Retrieve all instances of model. /// </summary> /// <returns></returns> public static BoolMessageItem <IList <T> > GetAll() { IEntityService <T> service = ActiveRecordRegistration.GetService <T>(); return(service.GetAll(new ActionContext())); }
/// <summary> /// Change the current password. /// </summary> /// <param name="userName">username of the account for which the password is being changed.</param> /// <param name="currentPassword">Existing password on file.</param> /// <param name="newPassword">New password</param> /// <param name="confirmPassword">Confirm the password. must be same as new password.</param> /// <returns></returns> public static BoolResult <Account> ChangePassword(string userName, string currentPassword, string newPassword, string confirmPassword) { AccountService service = ActiveRecordRegistration.GetService <Account>() as AccountService; return(service.ChangePassword(userName, currentPassword, newPassword, confirmPassword)); }
/// <summary> /// Register the user. /// </summary> /// <param name="userName"></param> /// <param name="email"></param> /// <param name="password"></param> /// <param name="confirmPassword"></param> /// <returns></returns> public static BoolResult <Account> Create(string userName, string email, string password, string confirmPassword) { AccountService service = ActiveRecordRegistration.GetService <Account>() as AccountService; return(service.Create(userName, email, password, confirmPassword)); }
/// <summary> /// Try logging in to server. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public static BoolMessage LogOn(string userName, string password, bool rememberUser) { AccountService service = ActiveRecordRegistration.GetService <Account>() as AccountService; return(service.LogOn(userName, password, rememberUser)); }
/// <summary> /// Provide a static method for verifying a user is registerd/exists. /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public static BoolMessage VerifyUser(string username, string password) { AccountService service = ActiveRecordRegistration.GetService <Account>() as AccountService; return(service.VerifyUser(username, password)); }
/// <summary> /// Delete the model associated with the id. /// </summary> /// <param name="id"></param> /// <returns></returns> public static BoolMessage Delete(int id) { IService <T> service = ActiveRecordRegistration.GetService <T>(); return(service.Delete(new ActionContext(id, true))); }