Example #1
0
        public async Task <int> SeedGroupAsync(ApplicationDbContext context)
        {
            var groups = new Product_Group[]
            {
                new Product_Group()
                {
                    Id = "abc1", GroupName = Enum.Parse <GroupType>("Fireplace")
                },
                new Product_Group()
                {
                    Id = "abc2", GroupName = Enum.Parse <GroupType>("Finished_Models")
                },
                new Product_Group()
                {
                    Id = "abc3", GroupName = Enum.Parse <GroupType>("Project")
                },
                new Product_Group()
                {
                    Id = "abc4", GroupName = Enum.Parse <GroupType>("Accessories")
                },
            };

            foreach (var group in groups)
            {
                await context.Product_Groups.AddAsync(group);
            }

            await context.SaveChangesAsync();

            return(groups.Length);
        }
 public async Task CreateAsync([FromBody] Product_Group item)
 {
     try
     {
         _context.Product_Group.Add(item);
         await _context.SaveChangesAsync();
     }catch (Exception ex) {
         throw new Exception(ex.Message);
     }
 }
        public async Task UpdateAsync(int id, [FromBody] Product_Group item)
        {
            var result = _context.Product_Group.FirstOrDefault(t => t.Id == id);

            result.Id   = item.Id;
            result.Name = item.Name;
            try
            {
                _context.Product_Group.Update(result);
                await _context.SaveChangesAsync();
            }catch (Exception ex) {
                throw new Exception(ex.Message);
            }
        }
        public async Task <List <Product_Group> > GetByIdAsync(int id)
        {
            Product_Group objectProductInfo = await _context.Product_Group.FindAsync(id);

            List <Product_Group> product = new List <Product_Group>();

            try
            {
                product.Add(objectProductInfo);
            }catch (Exception ex) {
                throw new Exception(ex.Message);
            }
            return(product);
        }
        public async Task CreateAsync(string name)
        {
            var group = new Product_Group
            {
                Id         = Guid.NewGuid().ToString(),
                GroupName  = Enum.Parse <GroupType>(name),
                CreatedOn  = DateTime.UtcNow,
                ModifiedOn = DateTime.UtcNow,
            };

            await this.groupRepository.AddAsync(group);

            await this.groupRepository.SaveChangesAsync();
        }
Example #6
0
        public async Task <int> SeedProdcutAsync(ApplicationDbContext context)
        {
            var user = new ApplicationUser
            {
                Id             = Guid.NewGuid().ToString(),
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var groups = new Product_Group[]
            {
                new Product_Group()
                {
                    Id = "abc1", GroupName = Enum.Parse <GroupType>("Fireplace")
                },
                new Product_Group()
                {
                    Id = "abc2", GroupName = Enum.Parse <GroupType>("Finished_Models")
                },
                new Product_Group()
                {
                    Id = "abc3", GroupName = Enum.Parse <GroupType>("Project")
                },
                new Product_Group()
                {
                    Id = "abc4", GroupName = Enum.Parse <GroupType>("Accessories")
                },
            };

            var products = new Product[]
            {
                new Product()
                {
                    Id        = "abc",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Гк Мая",
                    UserId    = user.Id,
                },

                new Product()
                {
                    Id        = "abc2",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Гк Оливия",
                    UserId    = user.Id,
                },
            };

            foreach (var product in products)
            {
                await context.Products.AddAsync(product);
            }

            await context.SaveChangesAsync();

            return(groups.Length);
        }
Example #7
0
        public async Task <int> SeedCommentsAsync(ApplicationDbContext context)
        {
            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var groups = new Product_Group[]
            {
                new Product_Group()
                {
                    Id = "abc1", GroupName = Enum.Parse <GroupType>("Fireplace")
                },
                new Product_Group()
                {
                    Id = "abc2", GroupName = Enum.Parse <GroupType>("Finished_Models")
                },
                new Product_Group()
                {
                    Id = "abc3", GroupName = Enum.Parse <GroupType>("Project")
                },
                new Product_Group()
                {
                    Id = "abc4", GroupName = Enum.Parse <GroupType>("Accessories")
                },
            };

            var products = new Product[]
            {
                new Product()
                {
                    Id        = "abc",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Гк Мая",
                    UserId    = user.Id,
                },

                new Product()
                {
                    Id        = "abc2",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Гк Оливия",
                    UserId    = user.Id,
                },

                new Product()
                {
                    Id        = "abc3",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Гк Амелия",
                    UserId    = user.Id,
                },
            };

            var fireplaces = new List <Fireplace_chamber>
            {
                new Fireplace_chamber
                {
                    Id            = "abc1",
                    Power         = "10w",
                    Chimney       = "200Ф",
                    CreatedOn     = DateTime.UtcNow,
                    Description   = "Some description test 1",
                    GroupId       = groups[0].Id,
                    ImagePath     = "https://cdn11.bigcommerce.com/s-j2bzz1q4/images/stencil/1280x1280/products/206/4809/Biltmore-Wood-Burning-Fireplace-2-main__66102.1541203308.jpg?c=2&imbypass=on",
                    Price         = 1800.00M,
                    Size          = "60 / 40 / h50",
                    TypeOfChamber = TypeOfChamber.Basic,
                    ProductId     = products[0].Id,
                },
                new Fireplace_chamber
                {
                    Id            = "abc2",
                    Power         = "15w",
                    Chimney       = "200Ф",
                    CreatedOn     = DateTime.UtcNow,
                    Description   = "Some description test 2",
                    GroupId       = groups[0].Id,
                    ImagePath     = "https://cdn11.bigcommerce.com/s-j2bzz1q4/images/stencil/1280x1280/products/206/4809/Biltmore-Wood-Burning-Fireplace-2-main__66102.1541203308.jpg?c=2&imbypass=on",
                    Price         = 1200.00M,
                    Size          = "40 / 20 / h30",
                    TypeOfChamber = TypeOfChamber.Basic,
                    ProductId     = products[1].Id,
                },
                new Fireplace_chamber
                {
                    Id            = "abc3",
                    Power         = "17w",
                    Chimney       = "200Ф",
                    CreatedOn     = DateTime.UtcNow,
                    Description   = "Some description test 3",
                    GroupId       = groups[0].Id,
                    ImagePath     = "https://cdn11.bigcommerce.com/s-j2bzz1q4/images/stencil/1280x1280/products/206/4809/Biltmore-Wood-Burning-Fireplace-2-main__66102.1541203308.jpg?c=2&imbypass=on",
                    Price         = 1350.00M,
                    Size          = "45 / 25 / h35",
                    TypeOfChamber = TypeOfChamber.Basic,
                    ProductId     = products[1].Id,
                },
            };

            var comments = new List <Comment>
            {
                new Comment()
                {
                    Id        = "comId1",
                    FullName  = "Павлина Якимова",
                    Email     = "*****@*****.**",
                    Content   = "Some content",
                    CreatedOn = DateTime.UtcNow,
                    ProductId = products[0].Id,
                },
                new Comment()
                {
                    Id        = "comId2",
                    FullName  = "Методи Якимов",
                    Email     = "*****@*****.**",
                    Content   = "Some content 2",
                    CreatedOn = DateTime.UtcNow,
                    ProductId = products[0].Id,
                },
            };

            foreach (var product in products)
            {
                await context.Products.AddAsync(product);
            }

            foreach (var fireplace in fireplaces)
            {
                await context.Fireplace_Chambers.AddAsync(fireplace);
            }

            foreach (var comment in comments)
            {
                await context.Comments.AddAsync(comment);
            }

            await context.SaveChangesAsync();

            return(comments.Count);
        }
Example #8
0
        public async Task <int> SeedAccessorieAsync(ApplicationDbContext context)
        {
            var user = new ApplicationUser
            {
                Id             = "abc",
                FirstName      = "Nikolay",
                LastName       = "Doychev",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
            };

            var groups = new Product_Group[]
            {
                new Product_Group()
                {
                    Id = "abc1", GroupName = Enum.Parse <GroupType>("Fireplace")
                },
                new Product_Group()
                {
                    Id = "abc2", GroupName = Enum.Parse <GroupType>("Finished_Models")
                },
                new Product_Group()
                {
                    Id = "abc3", GroupName = Enum.Parse <GroupType>("Project")
                },
                new Product_Group()
                {
                    Id = "abc4", GroupName = Enum.Parse <GroupType>("Accessories")
                },
            };

            var products = new Product[]
            {
                new Product()
                {
                    Id        = "abc",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Аксесоар 1",
                    UserId    = user.Id,
                },

                new Product()
                {
                    Id        = "abc2",
                    CreatedOn = DateTime.UtcNow,
                    GroupId   = groups[0].Id,
                    Name      = "Аксесоар 2",
                    UserId    = user.Id,
                },
            };

            var accessories = new List <Accessorie>
            {
                new Accessorie
                {
                    Id          = "abc1",
                    CreatedOn   = DateTime.UtcNow,
                    GroupId     = groups[3].Id,
                    ProductId   = products[0].Id,
                    Description = "Some description test 1",
                    ImagePath   = "Some dummy picture 1",
                },
                new Accessorie
                {
                    Id          = "abc2",
                    CreatedOn   = DateTime.UtcNow,
                    GroupId     = groups[3].Id,
                    ProductId   = products[1].Id,
                    Description = "Some description test 2",
                    ImagePath   = "Some dummy picture 2",
                },
            };

            foreach (var product in products)
            {
                await context.Products.AddAsync(product);
            }

            foreach (var accessorie in accessories)
            {
                await context.Accessories.AddAsync(accessorie);
            }

            await context.SaveChangesAsync();

            return(accessories.Count);
        }