public QueryableCommand(IFolkeConnection connection, MappedClass mappedClass, string sql, params object[] parameters) { Connection = connection; Parameters = parameters; MappedClass = mappedClass; Sql = sql; }
public static void UpdateIdentityUserSchema <TKey>(this IFolkeConnection folkeConnection) where TKey : IEquatable <TKey> { folkeConnection.CreateOrUpdateTable <IdentityUser <TKey> >(); folkeConnection.CreateOrUpdateTable <IdentityUserClaim <IdentityUser <TKey>, TKey> >(); folkeConnection.CreateOrUpdateTable <IdentityUserLogin <IdentityUser <TKey>, TKey> >(); }
public FolkeList(IFolkeConnection connection, Type parent, object parentId, string[] joins) { this.connection = connection; this.parent = parent; this.parentId = parentId; this.joins = joins; }
// Configure is called after ConfigureServices is called. public void Configure( IApplicationBuilder app, IHostingEnvironment env, IFolkeConnection connection, RoleManager <Role> roleManager, UserManager <Account> userManager, ApplicationPartManager applicationPartManager) { app.UseIdentity(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(); app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("fr-FR") }); connection.UpdateIdentityUserSchema <int, Account>(); connection.UpdateIdentityRoleSchema <int, Account>(); connection.UpdateSchema(typeof(Account).GetTypeInfo().Assembly); connection.UpdateForumSchema <Account>(); using (var transaction = connection.BeginTransaction()) { CreateAdministrator(roleManager, userManager).GetAwaiter().GetResult(); transaction.Commit(); } if (env.IsDevelopment()) { CreateTypeScriptServices(applicationPartManager); } }
public static IApplicationBuilder UseFolkeCore( this IApplicationBuilder app, IFolkeConnection connection, IHostingEnvironment env, RoleManager <Role> roleManager, UserManager <User> userManager, ApplicationPartManager applicationPartManager, Action <FolkeCoreOptions> optionsAction) { app.UseIdentity(); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(); app.UseRequestLocalization(); connection.UpdateIdentityUserSchema <int, User>(); connection.UpdateIdentityRoleSchema <int, User>(); connection.UpdateSchema(typeof(User).GetTypeInfo().Assembly); using (var transaction = connection.BeginTransaction()) { var options = new FolkeCoreOptions(); optionsAction(options); CreateAdministrator(roleManager, userManager, options).GetAwaiter().GetResult(); transaction.Commit(); } if (env.IsDevelopment()) { CreateTypeScriptServices(applicationPartManager); } return(app); }
public ImageController(IFolkeConnection session, IForumUserService <TUser, TUserView> accountService, IImageStore imageStore, ForumsDataMapping <TUser, TUserView> forumsDataMapping) { this.session = session; this.accountService = accountService; this.imageStore = imageStore; this.forumsDataMapping = forumsDataMapping; }
public static void UpdateForumSchema <TUser>(this IFolkeConnection folkeConnection) { folkeConnection.CreateOrUpdateTable <Chat <TUser> >(); folkeConnection.CreateOrUpdateTable <LastChatView <TUser> >(); folkeConnection.CreateOrUpdateTable <Comment <TUser> >(); folkeConnection.CreateOrUpdateTable <Data.Forums.Forum>(); folkeConnection.CreateOrUpdateTable <LastForumView <TUser> >(); folkeConnection.CreateOrUpdateTable <Photo <TUser> >(); folkeConnection.CreateOrUpdateTable <PrivateMessage <TUser> >(); folkeConnection.CreateOrUpdateTable <PrivateMessageRecipient <TUser> >(); folkeConnection.CreateOrUpdateTable <PrivateMessageViewed <TUser> >(); folkeConnection.CreateOrUpdateTable <Thread <TUser> >(); folkeConnection.CreateOrUpdateTable <ThreadLastViewed <TUser> >(); folkeConnection.CreateOrUpdateTable <PhotoInThread <TUser> >(); folkeConnection.CreateOrUpdateTable <CommentInThread <TUser> >(); folkeConnection.CreateOrUpdateTable <ExternalLink>(); folkeConnection.CreateOrUpdateTable <Poll <TUser> >(); folkeConnection.CreateOrUpdateTable <PollPossibleAnswer <TUser> >(); folkeConnection.CreateOrUpdateTable <PollChosenAnswer <TUser> >(); folkeConnection.CreateOrUpdateTable <Tag>(); folkeConnection.CreateOrUpdateTable <TagThread <TUser> >(); }
public static IReadOnlyList <T> UpdateManyToMany <T, TParent, TChild>(this IFolkeConnection connection, TParent parent, IReadOnlyList <T> currentValues, ICollection <int> newValueIds) where T : class, IManyToManyTable <TParent, TChild>, new() where TParent : IFolkeTable where TChild : class, IFolkeTable, new() { return(connection.UpdateManyToMany(parent, currentValues, newValueIds, new FolkeTableManyToManyHelperWithIds <TChild>())); }
/// <summary> /// Creates the table for an identity of type TUser /// </summary> /// <typeparam name="TUser"></typeparam> /// <param name="folkeConnection"></param> public static void UpdateStringIdentityUserSchema <TUser>(this IFolkeConnection folkeConnection) where TUser : IdentityUser <TUser, string>, new() { folkeConnection.CreateOrUpdateTable <TUser>(); folkeConnection.CreateOrUpdateTable <IdentityUserClaim <TUser, string> >(); folkeConnection.CreateOrUpdateTable <IdentityUserLogin <TUser, string> >(); }
public OpNameController(IFolkeConnection session, INounService nounService, IAdjectiveService adjService) { _session = session; _nounService = nounService; _adjService = adjService; }
public static void UpdateIdentityRoleSchema <TKey, TUser>(this IFolkeConnection folkeConnection) where TKey : IEquatable <TKey> where TUser : IdentityUser <TUser, TKey> { folkeConnection.CreateOrUpdateTable <IdentityRole <TKey> >(); folkeConnection.CreateOrUpdateTable <IdentityUserRole <TUser, TKey> >(); folkeConnection.CreateOrUpdateTable <IdentityRoleClaim <TKey> >(); }
public void Configure(IApplicationBuilder app, IFolkeConnection connection, IHostingEnvironment environment, RoleManager <Role> roleManager, UserManager <User> userManager, ApplicationPartManager applicationPartManager) { app.UseFolkeCore(connection, environment, roleManager, userManager, applicationPartManager, options => { options.AdministratorEmail = "*****@*****.**"; options.AdministratorPassword = "******"; }); }
public IQueryableCommand <T> Build(IFolkeConnection connection) { if (query == null) { var select = FluentBaseBuilder <T, FolkeTuple> .Select(connection.Driver, connection.Mapper); query = prepare.Invoke(select); } return(query.Build(connection)); }
public TestManyToManyHelpers() { var driver = new MySqlDriver(); var newMapper = new Mapper(); connection = FolkeConnection.Create(driver, newMapper, TestHelpers.ConnectionString); connection.CreateOrUpdateTable <ParentClass>(); connection.CreateOrUpdateTable <ChildClass>(); connection.CreateOrUpdateTable <LinkClass>(); }
public PrivateMessageController(IFolkeConnection session, IForumUserService <TUser, TUserView> accountService, ForumsDataMapping <TUser, TUserView> forumsDataMapping, HtmlSanitizerService <TUser> htmlSanitizerService) { this.session = session; this.accountService = accountService; this.forumsDataMapping = forumsDataMapping; this.htmlSanitizerService = htmlSanitizerService; }
public ThreadController(IFolkeConnection session, IForumUserService <TUser, TUserView> accountService, ForumsDataMapping <TUser, TUserView> forumsDataMapping, HtmlSanitizerService <TUser> htmlSanitizerService, CommentService <Thread <TUser>, CommentInThread <TUser>, TUser, TUserView> commentService) { this.session = session; this.accountService = accountService; this.forumsDataMapping = forumsDataMapping; this.htmlSanitizerService = htmlSanitizerService; this.commentService = commentService; }
/// <summary> /// Construct an object, fill its primary key with the given id, and create any auto collection /// </summary> /// <param name="connection">The connection (for the auto collection constructor)</param> /// <param name="type">The type to construct</param> /// <param name="id">The primary key value</param> /// <returns>The object, whose primary key and collections are filled</returns> public object Construct(IFolkeConnection connection, Type type, object id) { var ret = constructor.Invoke(null); primaryKeyField?.PropertyMapping.PropertyInfo.SetValue(ret, id); if (collections != null) { foreach (var collection in collections) { collection.propertyInfo.SetValue(ret, collection.listConstructor.Invoke(new[] { connection, type, id, collection.listJoins })); } } return(ret); }
/// <summary> /// Updates a collection of items from a collection of item views. Existing items are updated or deleted. New items are added. /// </summary> /// <typeparam name="TChild">The database item</typeparam> /// <typeparam name="TChildView">A view of this database item. Matching items have same Id</typeparam> /// <param name="connection">The database connection</param> /// <param name="currentValues">The current value from the database</param> /// <param name="newValues">The new values</param> /// <param name="factory">A factory that create a new item</param> /// <param name="updater">A delegate that updates an existing item</param> public static List <TChild> UpdateCollectionFromViews <TChild, TChildView>(this IFolkeConnection connection, IReadOnlyCollection <TChild> currentValues, IReadOnlyCollection <TChildView> newValues, Func <TChildView, TChild> factory, Func <TChildView, TChild, bool> updater) where TChild : class, IFolkeTable, new() where TChildView : class, IFolkeTable, new() { var ret = new List <TChild>(); if (currentValues == null || !currentValues.Any()) { foreach (var childValue in newValues) { var child = factory(childValue); ret.Add(child); connection.Save(child); } return(ret); } var newValueToAdd = newValues.Where(x => currentValues.All(y => y.Id != x.Id)); foreach (var currentValue in currentValues) { var newValue = newValues.FirstOrDefault(x => x.Id == currentValue.Id); if (newValue == null) { connection.Delete(currentValue); } else { if (updater != null && updater(newValue, currentValue)) { connection.Update(currentValue); } ret.Add(currentValue); } } foreach (var childDto in newValueToAdd) { var child = factory(childDto); ret.Add(child); connection.Save(child); } return(ret); }
/// <summary> /// Update a collection of items using a collection of values. These values don't have an id to identity them, so a areEqual delegate /// must be given as a parameter. Existing items that is not in newValues are deleted. /// </summary> /// <typeparam name="TChild">The database item type</typeparam> /// <typeparam name="TChildView">The view type</typeparam> /// <param name="connection">The database connection</param> /// <param name="currentValues">The current value from the database</param> /// <param name="newValues">The new values</param> /// <param name="areEqual">Must return true if the two values are equal</param> /// <param name="factory">Create a new item</param> public static List <TChild> UpdateCollectionFromValues <TChild, TChildView>(this IFolkeConnection connection, IReadOnlyCollection <TChild> currentValues, IReadOnlyCollection <TChildView> newValues, Func <TChildView, TChild> factory, Func <TChildView, TChild, bool> areEqual) where TChild : class, IFolkeTable, new() { var ret = new List <TChild>(); if (currentValues == null || !currentValues.Any()) { foreach (var childValue in newValues) { var child = factory(childValue); connection.Save(child); ret.Add(child); } return(ret); } var newValueToAdd = newValues.Where(x => currentValues.All(y => !areEqual(x, y))); foreach (var currentValue in currentValues) { if (!newValues.Any(x => areEqual(x, currentValue))) { connection.Delete(currentValue); } else { ret.Add(currentValue); } } foreach (var childDto in newValueToAdd) { var child = factory(childDto); connection.Save(child); ret.Add(child); } return(ret); }
public IList <TChild> QueryExisting(IFolkeConnection connection, IList <int> dto) { return(dto.Any() ? connection.SelectAllFrom <TChild>().Where(c => c.Id.In(dto)).ToList() : null); }
public AdjectiveService(IFolkeConnection session) { _session = session; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IFolkeConnection connection, RoleManager <Role> roleManager, UserManager <User> userManager, ApplicationPartManager applicationPartManager) { // Default admin credentials must be specified here because they interact with ASP.NET Identity app.UseFolkeCore(connection, env, roleManager, userManager, applicationPartManager, options => { options.AdministratorEmail = Configuration["Data:DefaultAdministratorUserName"]; options.AdministratorPassword = Configuration["Data:DefaultAdministratorPassword"]; }); // Elm updates database schema connection.UpdateSchema(typeof(Adjective).GetTypeInfo().Assembly); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseMvc(); if (env.IsDevelopment()) { CreateTypeScriptServices(applicationPartManager); } }
public AdjectiveController(IFolkeConnection session, IAdjectiveService adjService) { _session = session; _adjService = adjService; }
public ChatController(IFolkeConnection session, IForumUserService <TUser, TUserView> userService, ChatDataMapping <TUser, TUserView> chatDataMapping) { this.session = session; this.userService = userService; this.chatDataMapping = chatDataMapping; }
public UserService(IFolkeConnection connection, IHttpContextAccessor httpContextAccessor, UserManager <User> userManager) : base(httpContextAccessor, userManager) { this.connection = connection; }
public ProductService(IFolkeConnection session) { this.session = session; }
public NounService(IFolkeConnection session) { _session = session; }
public static IReadOnlyList <T> UpdateManyToMany <T, TParent, TChild, TChildDto>(this IFolkeConnection connection, TParent parent, IReadOnlyList <T> currentValues, ICollection <TChildDto> newDtos, IManyToManyHelperConfiguration <TChild, TChildDto> helper) where T : class, IManyToManyTable <TParent, TChild>, new() where TParent : IFolkeTable where TChild : class, IFolkeTable, new() { if (newDtos == null) { newDtos = new List <TChildDto>(); } // Looking for any value in newDtos that is not in currentValues var valuesToAdd = newDtos.Where(v => currentValues == null || !currentValues.Any(cv => helper.AreEqual(cv.Child, v))).ToList(); var newValues = currentValues?.ToList() ?? new List <T>(); if (valuesToAdd.Any()) { // Query from the database the values that needs to be added to the parent var existingChildren = helper.QueryExisting(connection, valuesToAdd); foreach (var newDto in valuesToAdd) { var child = existingChildren?.SingleOrDefault(c => helper.AreEqual(c, newDto)); if (child == null) { // If the element to add does not exist in the database, create it (may fail if helper.Map/helper.UpdateDto is not implemented because one does not want to allow that) child = helper.Map(newDto); connection.Save(child); helper.UpdateDto(newDto, child); } // Create a new parent-child link with this value var newElement = new T { Child = child, Parent = parent }; connection.Save(newElement); newValues.Add(newElement); } } if (currentValues != null) { // Look for values to remove var valuesToRemove = currentValues.Where(cv => newDtos.All(nv => !helper.AreEqual(cv.Child, nv))).ToArray(); if (valuesToRemove.Any()) { connection.Delete <T>().From().Where(c => c.Id.In(valuesToRemove.Select(s => s.Id))).Execute(); foreach (var value in valuesToRemove) { newValues.Remove(value); } } } return(newValues); }
public static IReadOnlyList <T> UpdateManyToMany <T, TParent, TChild, TChildDto>(this IFolkeConnection connection, TParent parent, IReadOnlyList <T> currentValues, ICollection <TChildDto> newDtos, Func <TChildDto, TChild> mapper) where T : class, IManyToManyTable <TParent, TChild>, new() where TParent : IFolkeTable where TChild : class, IFolkeTable, new() where TChildDto : IFolkeTable { return(connection.UpdateManyToMany(parent, currentValues, newDtos, new FolkeTableManyToManyHelper <TChild, TChildDto>(mapper))); }
public IList <TChild> QueryExisting(IFolkeConnection connection, IList <TDto> dto) { var existingChildrenIds = dto.Where(c => c.Id != 0).Select(c => c.Id).ToArray(); return(existingChildrenIds.Any() ? connection.SelectAllFrom <TChild>().Where(c => c.Id.In(existingChildrenIds)).ToList() : null); }