コード例 #1
0
 public IList <CategoryModel> GetListCategory(string status)
 {
     try
     {
         var datas         = new List <CategoryModel>();
         var categoryStore = new CategoryStore();
         var dt            = categoryStore.GetListCategory(status);
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             var model = new CategoryModel()
             {
                 ID           = Int16.Parse(dt.Rows[i]["CATEGORY_ID"].ToString()),
                 PARENT_ID    = Int16.Parse(dt.Rows[i]["PARENT_ID"].ToString()),
                 TITLE        = dt.Rows[i]["CATEGORY_TITLE"].ToString(),
                 DESC         = dt.Rows[i]["CATEGORY_DESC"].ToString(),
                 TYPE         = dt.Rows[i]["CATEGORY_TYPE"].ToString(),
                 STATUS       = dt.Rows[i]["CATEGORY_STATUS"].ToString().Trim() == "1",
                 CREATED_USER = dt.Rows[i]["CREATED_USER"].ToString()
             };
             datas.Add(model);
         }
         return(datas);
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #2
0
        public CategoryModel GetCategoryById(string id)
        {
            try
            {
                var model         = new CategoryModel();
                var categoryStore = new CategoryStore();
                var dt            = categoryStore.GetCategoryById(id);
                if (dt.Rows.Count == 0)
                {
                    return(null);
                }
                model.ID        = int.Parse(dt.Rows[0]["CATEGORY_ID"].ToString());
                model.PARENT_ID = int.Parse(dt.Rows[0]["PARENT_ID"].ToString());
                model.TITLE     = dt.Rows[0]["CATEGORY_TITLE"].ToString();
                model.DESC      = dt.Rows[0]["CATEGORY_DESC"].ToString();
                model.TYPE      = dt.Rows[0]["CATEGORY_TYPE"].ToString();
                model.STATUS    = dt.Rows[0]["CATEGORY_STATUS"].ToString() == "1";
                return(model);
            }

            catch (Exception)
            {
                return(null);
            }
        }
コード例 #3
0
        public async Task GetAllCategoriesReturnsCategoriesWithDifferentBatchSizesTest(int itemCount)
        {
            var builder = Model.BuildStrategy.Clone();

            builder.TypeCreators.OfType <EnumerableTypeCreator>().Single().AutoPopulateCount = itemCount;

            var entries = Model.Create <List <Category> >();

            entries.Count.Should().Be(itemCount);

            var sut = new CategoryStore(Config.Storage);

            foreach (var entry in entries)
            {
                await sut.StoreCategory(entry, CancellationToken.None).ConfigureAwait(false);
            }

            var results = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = results.ToList();

            actual.Count.Should().BeGreaterOrEqualTo(entries.Count);

            foreach (var entry in entries)
            {
                var actualEntry = actual.First(x => x.Group == entry.Group && x.Name == entry.Name);

                actualEntry.Should().NotBeNull();
                actualEntry.Should().BeEquivalentTo(entry);
            }
        }
コード例 #4
0
        public async Task StoreCategoryOverwritesCategoryWithCaseInsensitiveNameMatchTest()
        {
            var first  = Model.Create <Category>().Set(x => x.Name = x.Name.ToUpperInvariant());
            var second = new Category
            {
                Group    = first.Group,
                Name     = first.Name.ToLowerInvariant(),
                Reviewed = !first.Reviewed,
                Visible  = !first.Reviewed
            };

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(first, CancellationToken.None).ConfigureAwait(false);

            await sut.StoreCategory(second, CancellationToken.None).ConfigureAwait(false);

            var categories = (await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false)).ToList();

            var actual = categories.First(
                x => x.Group == first.Group && x.Name.Equals(first.Name, StringComparison.OrdinalIgnoreCase));

            actual.Should().BeEquivalentTo(second);

            // The first entry should have been replaced with the second one based on the case
            // insensitive name match (name is the rowkey)
            categories.Should().NotContain(
                x => x.Group == second.Group && x.Name.Equals(first.Name, StringComparison.Ordinal));
        }
コード例 #5
0
        /// <summary>
        /// Syncs all tables.
        /// </summary>
        /// <returns>The all async.</returns>
        /// <param name="syncUserSpecific">If set to <c>true</c> sync user specific.</param>
        public async Task <bool> SyncAllAsync(bool syncUserSpecific)
        {
            if (!IsInitialized)
            {
                await InitializeAsync();
            }

            var taskList = new List <Task <bool> >();

            taskList.Add(CategoryStore.SyncAsync());
            taskList.Add(NotificationStore.SyncAsync());
            taskList.Add(SpeakerStore.SyncAsync());
            taskList.Add(SessionStore.SyncAsync());
            taskList.Add(WorkshopStore.SyncAsync());
            taskList.Add(SponsorStore.SyncAsync());
            taskList.Add(EventStore.SyncAsync());
            taskList.Add(ApplicationDataStore.SyncAsync());


            if (syncUserSpecific)
            {
                taskList.Add(FeedbackStore.SyncAsync());
                taskList.Add(FavoriteStore.SyncAsync());
            }

            var successes = await Task.WhenAll(taskList).ConfigureAwait(false);

            return(successes.Any(x => !x));//if any were a failure.
        }
コード例 #6
0
        public void StoreCategoryThrowsExceptionWithNullCategoryTest()
        {
            var sut = new CategoryStore(Config.Storage);

            Func <Task> action = async() => await sut.StoreCategory(null, CancellationToken.None).ConfigureAwait(false);

            action.Should().Throw <ArgumentNullException>();
        }
コード例 #7
0
        public CategoriesPage()
        {
            var categoryStore = new CategoryStore();
            var pageService   = new PageService();

            ViewModel = new CategoriesPageViewModel(categoryStore, pageService);
            InitializeComponent();
        }
コード例 #8
0
        public CategoryDetailPage(CategoryViewModel viewModel)
        {
            InitializeComponent();
            var categoryStore = new CategoryStore();
            var pageService   = new PageService();

            Title          = (viewModel.Description == null) ? "New Category" : "Edit Category";
            BindingContext = new CategoryDetailViewModel(viewModel ?? new CategoryViewModel(), categoryStore, pageService);
        }
コード例 #9
0
        public void CreateCategoryThrowsExceptionWithInvalidNameTest(string name)
        {
            var sut = new CategoryStore(Config.Storage);

            Func <Task> action = async() => await sut.CreateCategory(CategoryGroup.Gender, name, CancellationToken.None)
                                 .ConfigureAwait(false);

            action.Should().Throw <ArgumentException>();
        }
コード例 #10
0
ファイル: Prog.cs プロジェクト: OmaraliA/.NET-
        public List <Category> ReadCategory()
        {
            var categoryStore = new CategoryStore()
            {
                Path = categoryPath
            };
            var categoryList = categoryStore.GetCollection();

            return(categoryList);
        }
コード例 #11
0
        public async Task GetCategoryReturnsNullWhenCategoryNotFoundTest()
        {
            var category = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            var actual = await sut.GetCategory(category.Group, category.Name, CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeNull();
        }
コード例 #12
0
        public async Task CreateCategoryStoresNewCategoryTest()
        {
            var expected = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            await sut.CreateCategory(expected.Group, expected.Name, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            categories.Should().Contain(x => x.Group == expected.Group && x.Name == expected.Name);
        }
コード例 #13
0
        public async Task GetCategoryReturnsStoredCategoryTest()
        {
            var category = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(category, CancellationToken.None).ConfigureAwait(false);

            var actual = await sut.GetCategory(category.Group, category.Name, CancellationToken.None)
                         .ConfigureAwait(false);

            actual.Should().BeEquivalentTo(category);
        }
コード例 #14
0
        static void Main(string[] args)
        {
            var categoryStore = new CategoryStore()
            {
                Path = categoryPath
            };
            var categorytList = categoryStore.GetCollection();


            foreach (var item in categorytList)
            {
                Console.WriteLine(item.Id + " " + item.Weight);
            }
        }
コード例 #15
0
        public async Task StoreCategoryWritesCategoryWithNonAlphabetCharactersTest(string categoryName)
        {
            var expected = Model.Create <Category>().Set(x => x.Name = categoryName);

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(expected, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = categories.First(x => x.Group == expected.Group && x.Name == expected.Name);

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #16
0
        public async Task CreateCategoryStoresNewCategoryWithReviewedAndVisibleAsFalseAndZeroLinkCountTest()
        {
            var expected = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            await sut.CreateCategory(expected.Group, expected.Name, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = categories.Single(x => x.Group == expected.Group && x.Name == expected.Name);

            actual.Reviewed.Should().BeFalse();
            actual.Visible.Should().BeFalse();
            actual.LinkCount.Should().Be(0);
        }
コード例 #17
0
 /// <summary>
 /// Drops all tables from the database and updated DB Id
 /// </summary>
 /// <returns>The everything async.</returns>
 public Task DropEverythingAsync()
 {
     Settings.UpdateDatabaseId();
     CategoryStore.DropTable();
     EventStore.DropTable();
     NotificationStore.DropTable();
     SessionStore.DropTable();
     WorkshopStore.DropTable();
     SpeakerStore.DropTable();
     SponsorStore.DropTable();
     FeedbackStore.DropTable();
     FavoriteStore.DropTable();
     ApplicationDataStore.DropTable();
     IsInitialized = false;
     return(Task.FromResult(true));
 }
コード例 #18
0
        /// <summary>
        /// Attempts to read both the Categories and Replays store
        /// </summary>
        public bool Read()
        {
            try
            {
                cats = new CategoryStore();
                cats.ReadXml(CategoriesFilename);

                recs = new ReplayStore();
                recs.ReadXml(ReplaysFilename);
                return(true);
            }
            catch
            {
            }
            return(false);
        }
コード例 #19
0
        public async Task CreateCategoryIgnoresExistingCategoryTest()
        {
            var expected = Model.Create <Category>().Set(x => x.Reviewed = true).Set(x => x.Visible = true)
                           .Set(x => x.LinkCount = Math.Abs(Environment.TickCount));

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(expected, CancellationToken.None).ConfigureAwait(false);

            await sut.CreateCategory(expected.Group, expected.Name, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = categories.Single(x => x.Group == expected.Group && x.Name == expected.Name);

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #20
0
        public async Task GetAllCategoriesReturnsEmptyWhenTableNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the table client
            var client = storageAccount.CreateCloudTableClient();

            var table = client.GetTableReference("Categories");

            await table.DeleteIfExistsAsync().ConfigureAwait(false);

            var sut = new CategoryStore(Config.Storage);

            var actual = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            actual.Should().BeEmpty();
        }
コード例 #21
0
        public async Task StoreCategoryWritesUpdatedCategoryToStorageTest()
        {
            var expected = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(expected, CancellationToken.None).ConfigureAwait(false);

            expected.Reviewed = !expected.Reviewed;
            expected.Visible  = !expected.Visible;

            await sut.StoreCategory(expected, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = categories.First(x => x.Group == expected.Group && x.Name == expected.Name);

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #22
0
 public bool CategoryChangeStatus(string id, string status)
 {
     try
     {
         var categoryStore = new CategoryStore();
         var dt            = categoryStore.CategoryChangeStatus(id, status);
         if (dt)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #23
0
 public bool UpdateCategory(CategoryModel model)
 {
     try
     {
         var categoryStore = new CategoryStore();
         var dt            = categoryStore.UpdateCategory(model);
         if (dt)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #24
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            ErrorVisible = false;

            ErrorItemsVisible = false;

            IsBusy = true;

            try
            {
                Categories.Clear();
                var categories = await CategoryStore.GetItemsAsync(MainCategory.Id, true);

                if (categories.Count() == 0)
                {
                    IsBusy            = false;
                    ErrorItemsVisible = true;
                    return;
                }

                foreach (var category in categories)
                {
                    Categories.Add(category);
                }
                OnPropertyChanged("Categories");
                IsBusy = false;
            }
            catch (Exception)
            {
                IsBusy       = false;
                Content      = false;
                ErrorVisible = true;
            }
        }
コード例 #25
0
        async Task ExecuteLoadCategoryCommand()
        {
            IsBusy = true;

            try
            {
                Categories.Clear();
                var items = await CategoryStore.GetItemsAsync(true);

                foreach (var item in items)
                {
                    Categories.Add(item);
                }
                _ = ExecuteLoadProductCommand();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #26
0
        public async Task StoreCategoryCreatesTableAndWritesCategoryWhenTableNotFoundTest()
        {
            // Retrieve storage account from connection-string
            var storageAccount = CloudStorageAccount.Parse(Config.Storage.ConnectionString);

            // Create the table client
            var client = storageAccount.CreateCloudTableClient();

            var table = client.GetTableReference("Categories");

            await table.DeleteIfExistsAsync().ConfigureAwait(false);

            var expected = Model.Create <Category>();

            var sut = new CategoryStore(Config.Storage);

            await sut.StoreCategory(expected, CancellationToken.None).ConfigureAwait(false);

            var categories = await sut.GetAllCategories(CancellationToken.None).ConfigureAwait(false);

            var actual = categories.First(x => x.Group == expected.Group && x.Name == expected.Name);

            actual.Should().BeEquivalentTo(expected);
        }
コード例 #27
0
 public void ReadCategories()
 {
     cats = new CategoryStore();
     cats.ReadXml(CategoriesFilename);
 }
コード例 #28
0
        public static async Task InitializeAsync(IServiceProvider services)
        {
            var databaseDbContext = services.GetRequiredService <StoreOrderDbContext>();
            var logger            = services.GetRequiredService <ILogger <StoreOrderDbContext> >();

            // migration db
            databaseDbContext.Database.EnsureCreated();

            if (!databaseDbContext.Roles.Any())
            {
                string password = "******";
                var    hashPass = Helpers.SercurityHelper.GenerateSaltedHash(password);

                //// I will add 1 user to one Role
                //var book1 = new Book();
                //var book2 = new Book();
                var roleAdmin = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleAdmin, Desc = "Admin of Store"
                };
                var roleOrderUser = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleOrderUser, Desc = "NV Order of Store"
                };
                var roleCookieUser = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleCookieUser, Desc = "NV phụ bếp of Store"
                };
                var rolePayUser = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RolePayUser, Desc = "Nv Thanh toán of Store"
                };
                var roleCustomerUser = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleCustomerUser, Desc = "Role Account of Customer"
                };

                //// I create the User
                //var lib = new Library();
                var user1 = new User {
                    Id = Guid.NewGuid().ToString(), Age = 29, BirthDay = new DateTime(1991, 1, 1).ToUniversalTime(), CountLoginFailed = 0, FirstName = "admin", LastName = "admin", IsActived = 1, Email = "*****@*****.**", UserName = "******", HashPassword = hashPass.Hash, SaltPassword = hashPass.Salt, Gender = 1, OldPassword = hashPass.Hash + ";" + hashPass.Salt, PhoneNumber = "1234567"
                };
                var nv1 = new User {
                    Id = Guid.NewGuid().ToString(), Age = 29, BirthDay = new DateTime(1991, 1, 1).ToUniversalTime(), CountLoginFailed = 0, FirstName = "nv1", LastName = "nv1", IsActived = 1, Email = "*****@*****.**", UserName = "******", HashPassword = hashPass.Hash, SaltPassword = hashPass.Salt, Gender = 1, OldPassword = hashPass.Hash + ";" + hashPass.Salt, PhoneNumber = "1234567"
                };
                var nv2 = new User {
                    Id = Guid.NewGuid().ToString(), Age = 29, BirthDay = new DateTime(1991, 1, 1).ToUniversalTime(), CountLoginFailed = 0, FirstName = "nv2", LastName = "nv2", IsActived = 1, Email = "*****@*****.**", UserName = "******", HashPassword = hashPass.Hash, SaltPassword = hashPass.Salt, Gender = 1, OldPassword = hashPass.Hash + ";" + hashPass.Salt, PhoneNumber = "1234567"
                };
                var nv3 = new User {
                    Id = Guid.NewGuid().ToString(), Age = 29, BirthDay = new DateTime(1991, 1, 1).ToUniversalTime(), CountLoginFailed = 0, FirstName = "nv3", LastName = "nv3", IsActived = 1, Email = "*****@*****.**", UserName = "******", HashPassword = hashPass.Hash, SaltPassword = hashPass.Salt, Gender = 1, OldPassword = hashPass.Hash + ";" + hashPass.Salt, PhoneNumber = "1234567"
                };

                //// I create two UserToRole which I need them
                //// To map between the users and the role
                //var b2lib1 = new Library2Book();
                //var b2lib2 = new Library2Book();
                var userToRole1 = new UserToRole();
                var userToRole2 = new UserToRole();
                var userToRole3 = new UserToRole();
                var userToRole4 = new UserToRole();
                //// Mapping the first book to the library.
                //// Changed userToRole1.Role to userToRole2.Role
                //// Changed b2lib2.Library to b2lib1.Library
                //b2lib1.Book = book1;
                //b2lib1.Library = lib;
                userToRole1.Role = roleAdmin;
                userToRole1.User = user1;

                //// I map the second book to the library.
                //b2lib2.Book = book2;
                //b2lib2.Library = lib;
                userToRole2.Role = roleOrderUser;
                userToRole2.User = nv1;

                userToRole3.Role = roleCookieUser;
                userToRole3.User = nv2;

                userToRole4.Role = rolePayUser;
                userToRole4.User = nv3;

                //// Linking the books (Library2Book table) to the library
                //lib.Library2Books.Add(b2lib1);
                //lib.Library2Books.Add(b2lib2);
                roleAdmin.UserToRoles.Add(userToRole1);
                roleOrderUser.UserToRoles.Add(userToRole2);
                roleCookieUser.UserToRoles.Add(userToRole3);
                rolePayUser.UserToRoles.Add(userToRole4);

                //// Adding the data to the DbContext.
                //myDb.Libraries.Add(lib);
                databaseDbContext.Roles.Add(roleAdmin);
                databaseDbContext.Users.Add(user1);
                databaseDbContext.SaveChanges();

                databaseDbContext.Roles.Add(roleOrderUser);
                databaseDbContext.Users.Add(nv1);
                databaseDbContext.SaveChanges();

                databaseDbContext.Roles.Add(roleCookieUser);
                databaseDbContext.Users.Add(nv2);
                databaseDbContext.SaveChanges();

                databaseDbContext.Roles.Add(rolePayUser);
                databaseDbContext.Users.Add(nv3);
                databaseDbContext.SaveChanges();

                //myDb.Books.Add(book1);
                //myDb.Books.Add(book2);

                //// Save the changes and everything should be working!
                //myDb.SaveChanges();

                //await databaseDbContext.SaveChangesAsync();

                logger.LogInformation("DatabaseDbContext", "---initial data of Surveys success---");
            }

            if (databaseDbContext.Roles.Count() == 4)
            {
                var roleCustomerUser = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleCustomerUser, Desc = "Role Account of Customer"
                };
                await databaseDbContext.Roles.AddAsync(roleCustomerUser);

                await databaseDbContext.SaveChangesAsync();
            }

            if (databaseDbContext.Roles.Count() == 5)
            {
                var roleSysAdmin = new Role {
                    Id = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), RoleName = RoleTypeHelper.RoleSysAdmin, Desc = "Role SysAdmin"
                };
                await databaseDbContext.Roles.AddAsync(roleSysAdmin);

                await databaseDbContext.SaveChangesAsync();
            }

            if (!databaseDbContext.CategoryStores.Any())
            {
                var catStore = new CategoryStore {
                    Id = Guid.NewGuid().ToString(), Name = "Nhà hàng"
                };
                await databaseDbContext.CategoryStores.AddAsync(catStore);

                await databaseDbContext.SaveChangesAsync();

                var useradmin    = databaseDbContext.Users.FirstOrDefault(x => x.UserName.ToLower().Equals("admin01"));
                var store1       = new Store();
                var optionSize   = new StoreOption();
                var optionToping = new StoreOption();
                if (useradmin != null)
                {
                    if (!databaseDbContext.Stores.Any())
                    {
                        store1 = new Store
                        {
                            Id = Guid.NewGuid().ToString(),
                            CategoryStoreId = catStore.Id,
                            StatusStore     = 1,
                            StoreAddress    = "Số 1, Xuân thủy, Cầu Giấy, Việt Nam",
                            StoreName       = "Store 1",
                            CreateByUserId  = useradmin.Id,
                        };

                        var lstStoreTable = new List <StoreTable>()
                        {
                            new StoreTable
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Location     = 1,
                                LocationUnit = 1,
                                StoreId      = store1.Id,
                                TableCode    = Guid.NewGuid().ToString(),
                                TableName    = "Bàn 1",
                                TableStatus  = 1
                            },
                            new StoreTable
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Location     = 1,
                                LocationUnit = 1,
                                StoreId      = store1.Id,
                                TableCode    = Guid.NewGuid().ToString(),
                                TableName    = "Bàn 2",
                                TableStatus  = 1
                            },
                            new StoreTable
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Location     = 1,
                                LocationUnit = 1,
                                StoreId      = store1.Id,
                                TableCode    = Guid.NewGuid().ToString(),
                                TableName    = "Bàn 3",
                                TableStatus  = 1
                            },
                            new StoreTable
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Location     = 1,
                                LocationUnit = 1,
                                StoreId      = store1.Id,
                                TableCode    = Guid.NewGuid().ToString(),
                                TableName    = "Bàn 4",
                                TableStatus  = 1
                            },
                            new StoreTable
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Location     = 1,
                                LocationUnit = 1,
                                StoreId      = store1.Id,
                                TableCode    = Guid.NewGuid().ToString(),
                                TableName    = "Bàn 5",
                                TableStatus  = 1
                            }
                        };

                        optionSize = new StoreOption {
                            OptionId = Guid.NewGuid().ToString(), StoreId = store1.Id, StoreOptionName = "size", StoreOptionDescription = "Kích thước"
                        };
                        optionToping = new StoreOption {
                            OptionId = Guid.NewGuid().ToString(), StoreId = store1.Id, StoreOptionName = "toping", StoreOptionDescription = "Toping"
                        };

                        var lstStoreOption = new List <StoreOption>()
                        {
                            optionSize,
                            optionToping,
                            new StoreOption {
                                OptionId = Guid.NewGuid().ToString(), StoreId = store1.Id, StoreOptionName = "color", StoreOptionDescription = "Màu sắc"
                            },
                            new StoreOption {
                                OptionId = Guid.NewGuid().ToString(), StoreId = store1.Id, StoreOptionName = "class", StoreOptionDescription = "Lớp"
                            },
                            new StoreOption {
                                OptionId = Guid.NewGuid().ToString(), StoreId = store1.Id, StoreOptionName = "devo", StoreOptionDescription = "Dễ vỡ"
                            },
                        };


                        store1.StoreTables  = lstStoreTable;
                        store1.StoreOptions = lstStoreOption;

                        await databaseDbContext.Stores.AddAsync(store1);

                        await databaseDbContext.SaveChangesAsync();
                    }

                    if (!databaseDbContext.CategoryProducts.Any())
                    {
                        var catProduct = new CategoryProduct
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = "Danh mục 1",
                            Slug         = "danh-muc-1",
                            Code         = "danhmuc1code",
                            ParentId     = null,
                        };

                        var lstProducts = new List <Product>()
                        {
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 1", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 02", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 03", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 04", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 05", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 06", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 07", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 08", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 09", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 10", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 11", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 12", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 13", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                            new Product {
                                Id = Guid.NewGuid().ToString(), CategoryId = catProduct.Id, ProductName = "Sản phẩm 14", CreateByUserId = useradmin.Id, StoreId = store1.Id
                            },
                        };
                        catProduct.Products = lstProducts;

                        await databaseDbContext.AddAsync(catProduct);

                        await databaseDbContext.SaveChangesAsync();
                    }
                }
            }

            if (!databaseDbContext.Permissions.Any())
            {
                await databaseDbContext.Permissions.AddRangeAsync(new List <Permission>() {
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.SysAdmin.ImportLocation
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.SysAdmin.ViewLogs
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.SysAdmin.DeleteLogs
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Account.Create
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Account.Delete
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Account.Edit
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Account.View
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Users.View
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Users.Create
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Users.Edit
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Users.Delete
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.SysAdmin.GetListCategoryStore
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.GetListStoreOption
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.GetMenuProduct
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.CreateProduct
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.DeleteProduct
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.UpdateProduct
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.AdminStore.GetListProduct
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.ConfirmOrder
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.ConfirmPayOrder
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.CreateOrder
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetCategoryProductsForEmployee
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListOrderWithTableOrProductName
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListProductsOfStoreForEmployee
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListProductsOfStoreForEmployeeV2
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListProductsOfStoreWithCategoryForEmployee
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListProductsOfStoreWithCategoryForEmployeeV2
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetListTables
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetOrderProductsWithTable
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.GetOrderWithTableViewProductsWithTableId
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Employee.UpdateOrder
                    },
                    new Permission {
                        Id = Guid.NewGuid().ToString(), PermissionName = Permissions.Upload.UploadFile
                    },
                });

                await databaseDbContext.SaveChangesAsync();
            }

            if (!databaseDbContext.RoleToPermissions.Any())
            {
                // get role
                var roleSysadmin = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RoleSysAdmin);

                var roleAdminStore = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RoleAdmin);

                var roleOrderUser = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RoleOrderUser);

                var roleCookieUser = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RoleCookieUser);

                var rolePayUser = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RolePayUser);

                #region update roleSysAdmin
                var permissionsSysAdmin = databaseDbContext.Permissions
                                          .Where(x => x.PermissionName == Permissions.SysAdmin.ImportLocation ||
                                                 x.PermissionName == Permissions.SysAdmin.ViewLogs ||
                                                 x.PermissionName == Permissions.SysAdmin.DeleteLogs ||
                                                 x.PermissionName == Permissions.Account.Create ||
                                                 x.PermissionName == Permissions.Account.Delete ||
                                                 x.PermissionName == Permissions.Account.Edit ||
                                                 x.PermissionName == Permissions.Account.View ||
                                                 x.PermissionName == Permissions.SysAdmin.GetListStores ||
                                                 x.PermissionName == Permissions.SysAdmin.GetListCategoryStore
                                                 ).Select(x => x).ToList();

                foreach (var permission in permissionsSysAdmin)
                {
                    // add Permissions To Role
                    roleSysadmin.RoleToPermissions.Add(new RoleToPermission
                    {
                        Permission = permission,
                        Role       = roleSysadmin,
                    });
                }
                // save to db
                await databaseDbContext.SaveChangesAsync();

                #endregion

                #region Update RoleAdminStore
                var permissionsAdminStore = databaseDbContext.Permissions
                                            .Where(x => x.PermissionName == Permissions.AdminStore.GetMenuProduct ||
                                                   x.PermissionName == Permissions.AdminStore.GetListStoreOption ||
                                                   x.PermissionName == Permissions.AdminStore.GetListProduct ||
                                                   x.PermissionName == Permissions.AdminStore.CreateProduct ||
                                                   x.PermissionName == Permissions.AdminStore.UpdateProduct ||
                                                   x.PermissionName == Permissions.AdminStore.DeleteProduct ||
                                                   x.PermissionName == Permissions.Upload.UploadFile ||
                                                   x.PermissionName == Permissions.AdminStore.CreateCatProduct ||
                                                   x.PermissionName == Permissions.AdminStore.UpdateCatProduct ||
                                                   x.PermissionName == Permissions.AdminStore.DeleteCatProduct ||
                                                   x.PermissionName == Permissions.AdminStore.GetListCatProduct

                                                   ).Select(x => x).ToList();

                foreach (var permission in permissionsAdminStore)
                {
                    // add Permissions To Role
                    roleAdminStore.RoleToPermissions.Add(new RoleToPermission
                    {
                        Permission = permission,
                        Role       = roleAdminStore,
                    });
                }
                // save to db
                await databaseDbContext.SaveChangesAsync();

                #endregion

                #region Update RoleOrderUser
                var permissionsOrderUsers = databaseDbContext.Permissions
                                            .Where(x => x.PermissionName == Permissions.Employee.GetListTables ||
                                                   x.PermissionName == Permissions.Employee.GetCategoryProductsForEmployee ||
                                                   x.PermissionName == Permissions.Employee.GetListProductsOfStoreForEmployee ||
                                                   x.PermissionName == Permissions.Employee.GetListProductsOfStoreWithCategoryForEmployee ||
                                                   x.PermissionName == Permissions.Employee.GetListProductsOfStoreForEmployeeV2 ||
                                                   x.PermissionName == Permissions.Employee.GetListProductsOfStoreWithCategoryForEmployeeV2 ||
                                                   x.PermissionName == Permissions.Employee.CreateOrder ||
                                                   x.PermissionName == Permissions.Employee.UpdateOrder ||
                                                   x.PermissionName == Permissions.Employee.GetOrderProductsWithTable

                                                   ).Select(x => x).ToList();

                foreach (var permission in permissionsOrderUsers)
                {
                    // add Permissions To Role
                    roleOrderUser.RoleToPermissions.Add(new RoleToPermission
                    {
                        Permission = permission,
                        Role       = roleOrderUser,
                    });
                }
                // save to db
                await databaseDbContext.SaveChangesAsync();

                #endregion

                #region Update RoleCookieUser
                var permissionsOrderCookies = databaseDbContext.Permissions
                                              .Where(x => x.PermissionName == Permissions.Employee.GetOrderProductsWithTable ||
                                                     x.PermissionName == Permissions.Employee.GetListOrderWithTableOrProductName ||
                                                     x.PermissionName == Permissions.Employee.GetOrderWithTableViewProductsWithTableId ||
                                                     x.PermissionName == Permissions.Employee.ConfirmOrder ||
                                                     x.PermissionName == Permissions.Employee.UpdateOrderProductStatus
                                                     ).Select(x => x).ToList();

                foreach (var permission in permissionsOrderCookies)
                {
                    // add Permissions To Role
                    roleCookieUser.RoleToPermissions.Add(new RoleToPermission
                    {
                        Permission = permission,
                        Role       = roleCookieUser,
                    });
                }
                // save to db
                await databaseDbContext.SaveChangesAsync();

                #endregion

                #region Update rolePayUser
                var permissionsPayUsers = databaseDbContext.Permissions
                                          .Where(x => x.PermissionName == Permissions.Employee.ConfirmOrder ||
                                                 x.PermissionName == Permissions.Employee.ConfirmPayOrder
                                                 ).Select(x => x).ToList();

                foreach (var permission in permissionsPayUsers)
                {
                    // add Permissions To Role
                    rolePayUser.RoleToPermissions.Add(new RoleToPermission
                    {
                        Permission = permission,
                        Role       = rolePayUser,
                    });
                }
                // save to db
                await databaseDbContext.SaveChangesAsync();

                #endregion
            }

            if (!databaseDbContext.Users.Include(x => x.UserToRoles).ThenInclude(x => x.Role).Any(x => x.UserToRoles.Any(r => r.Role.RoleName == RoleTypeHelper.RoleSysAdmin)))
            {
                var roleSysAdmin = await databaseDbContext.Roles.FirstOrDefaultAsync(x => x.RoleName == RoleTypeHelper.RoleSysAdmin);

                string password     = "******";
                var    hashPass     = Helpers.SercurityHelper.GenerateSaltedHash(password);
                var    userSysAdmin = new User {
                    Id = Guid.NewGuid().ToString(), Age = 29, BirthDay = new DateTime(1991, 1, 1).ToUniversalTime(), CountLoginFailed = 0, FirstName = "sysadmin", LastName = "sysadmin", IsActived = 1, Email = "*****@*****.**", UserName = "******", HashPassword = hashPass.Hash, SaltPassword = hashPass.Salt, Gender = 1, OldPassword = hashPass.Hash + ";" + hashPass.Salt, PhoneNumber = "0349801673"
                };

                roleSysAdmin.UserToRoles.Add(new UserToRole
                {
                    Role = roleSysAdmin,
                    User = userSysAdmin,
                });

                // save to db
                await databaseDbContext.SaveChangesAsync();
            }
        }
コード例 #29
0
 public CategoriesController(CategoryStore categoryStore, CategoryReader categoryReader)
 {
     _categoryStore  = categoryStore;
     _categoryReader = categoryReader;
 }
コード例 #30
0
 public MenuViewModel()
 {
     Categories       = new ObservableCollection <Category>();
     LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand());
     DataStore        = new CategoryStore(new ApiService(DependencyService.Get <HttpClient>()));
 }
コード例 #31
0
ファイル: Program.cs プロジェクト: hyettdotme/PlayDrone2SQL
        public static void Main(string[] args)
        {
            string filePath = null;
            if (args.Length == 0)
            {
                throw new ArgumentException("Should be called with a Json PlayDrone file to import.");
            }

            filePath = args[0];

            var log = new Logger();
            var appConverter = new FileReader(log);

            var apps = appConverter.FileToModel(filePath);
            var count = apps.Count();

            // Setup connection
            var connectionString = ConfigurationManager.ConnectionStrings["MarketDbConnectionString"];
            using (var connection = new SqlConnection(connectionString.ConnectionString))
            {
                // Initialise app store with logger and connection
                var appSqlStore = new AppStore(connection);
                var appStore = new AppLogger(appSqlStore, appSqlStore, log);
                var categorySqlStore = new CategoryStore();
                var categoryCacheStore = new CategoryCache(categorySqlStore, categorySqlStore);
                var categoryStore = new CategoryLogger(categoryCacheStore, categoryCacheStore, log);

                // Assuming apps are added in order to save multiple queries to the database.
                var existingAppCount = appStore.Count();

                // Loop through apps. App store will save every 100,000 apps
                var appsToSave = new List<Models.App>();
                var appCounter = 0;
                for (int i = existingAppCount; i < count; i++)
                {
                    // Get the app from the list.
                    var app = apps[i];

                    // Store the app category if it doesn't exist.
                    if (!categoryStore.Exists(app.category))
                    {
                        var category = new Models.Category { Id = Guid.NewGuid(), Name = app.category };
                        categoryStore.Save(category);
                    }

                    // Lookup app category id.
                    var categoryId = categoryStore.GetId(app.category);

                    app.id = Guid.NewGuid();
                    app.categoryId = categoryId;
                    appsToSave.Add(app);
                    log.LogOperation(string.Format("App {0}/{1} added: {2}", i + 1, count, app.app_id));
                    appCounter++;

                    // Save apps
                    if(appCounter >= 100000)
                    {
                        appStore.SaveMany(appsToSave);
                        appsToSave.Clear();
                        appCounter = 0;
                    }
                }

                // Save the remainder
                appStore.SaveMany(appsToSave);

                log.LogOperation("DONE!!!!");
            }
        }