public ToyEntity GetOne(int id)
 {
     using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString))
     {
         using (SqlCommand cmd = c.CreateCommand())
         {
             cmd.CommandText = "SELECT * FROM Toys WHERE Id = @Id AND Active = 1";
             cmd.Parameters.AddWithValue("Id", id);
             c.Open();
             using (SqlDataReader Tab = cmd.ExecuteReader())
             {
                 if (Tab.Read())
                 {
                     ToyEntity S = new ToyEntity()
                     {
                         Id        = (int)Tab["Id"],
                         NameEN    = Tab["NameEN"].ToString(),
                         NameFR    = Tab["NameFR"].ToString(),
                         ImagePath = Tab["ImagePath"].ToString(),
                         Active    = (int)Tab["Active"]
                     };
                     return(S);
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
Exemple #2
0
        public ToyEntity CreateToy(ToyEntity newToy)
        {
            var newId = toys.OrderByDescending(r => r.Id).First().Id + 1;

            newToy.Id = newId;
            toys.Add(newToy);
            return(newToy);
        }
Exemple #3
0
        public bool UpdateToy(ToyEntity toy)
        {
            var res = GetToy(toy.Id);

            res.Name         = toy.Name ?? res.Name;
            res.EnterpriseID = toy.EnterpriseID;
            res.Category     = toy.Category ?? res.Category;
            res.Quantity     = toy.Quantity;
            res.Price        = toy.Price;
            res.CreatedDate  = toy.CreatedDate ?? res.CreatedDate;
            return(true);
        }
 public void Create(ToyEntity T)
 {
     using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["API"].ConnectionString))
     {
         using (SqlCommand cmd = c.CreateCommand())
         {
             if (T != null && T.NameEN != null && T.NameFR != null && T.ImagePath != null)
             {
                 cmd.CommandText = "SP_AddToy";
                 cmd.CommandType = CommandType.StoredProcedure;
                 SqlParameter NameEN    = new SqlParameter("NameEN", T.NameEN);
                 SqlParameter NameFR    = new SqlParameter("NameFR", T.NameFR);
                 SqlParameter ImagePath = new SqlParameter("ImagePath", T.ImagePath);
                 cmd.Parameters.Add(NameEN);
                 cmd.Parameters.Add(NameFR);
                 cmd.Parameters.Add(ImagePath);
                 c.Open();
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
 public ToyEntityViewModel(ToyEntity entity) =>
        public async Task Initialize(ToyStoreDbContext context)
        {
            var random     = new Random();
            var categories = new List <ToyCategoryEntity>();
            var toys       = new List <ToyEntity>();
            var sales      = new List <SaleEntity>();

            for (var i = 0; i < 20; i++)
            {
                var toyCategory = new ToyCategoryEntity
                {
                    Age       = (uint)random.Next(1, 20),
                    CareRules = Guid.NewGuid()
                                .ToString()
                                .Replace("-", "")
                                .ToUpper(),
                    WarrantyPeriod = (uint)random.Next(1, 128)
                };

                categories.Add(toyCategory);
            }

            for (var i = 0; i < 100; i++)
            {
                var toy = new ToyEntity
                {
                    Category = categories[random.Next(0, categories.Count)],
                    Photo    = $"photo{i + random.Next(0, 20000)}{Guid.NewGuid()}",
                    Price    = (decimal)(random.NextDouble() * random.Next(1, 5000)),
                    Producer = Guid.NewGuid()
                               .ToString()
                               .Substring(0, 7)
                               .Replace("-", ""),
                    WarehouseCount = (uint)random.Next(0, 30)
                };

                toys.Add(toy);
            }

            for (var i = 0; i < 1000; i++)
            {
                var selectedToy = toys[random.Next(0, toys.Count)];
                var discount    = random.Next(0, 80);
                var count       = random.Next(1, 100);
                var price       = selectedToy.Price * count * 100 / (discount == 0 ? 1 : discount);

                var sale = new SaleEntity
                {
                    Discount  = (uint)discount,
                    SaleDate  = DateTime.Now,
                    SaleSum   = price,
                    Toy       = selectedToy,
                    SaleCount = (uint)count
                };

                sales.Add(sale);
            }

            await context.ToyCategories.AddRangeAsync(categories);

            await context.Toys.AddRangeAsync(toys);

            await context.Sales.AddRangeAsync(sales);

            await context.SaveChangesAsync();
        }
Exemple #7
0
        public void TestInitialize()
        {
            _instance = new DMC();

            _testTV1 = new TVEntity()
            {
                Price      = 1000.00M,
                Model      = "VERY COOL 1 !",
                Resolution = "4K"
            };

            _testTV2 = new TVEntity()
            {
                Price      = 499.99M,
                Model      = "Not so COOL 2 !",
                Resolution = "1920*1080"
            };

            _testTV3 = new TVEntity()
            {
                Price      = 199.99M,
                Model      = "Cheap one 3",
                Resolution = "1024*720"
            };

            _testLaptop1 = new LaptopEntity()
            {
                Price = 5000.00M,
                Model = "SUPER 1",
                RAM   = 128,
                SSD   = 2048,
                HDD   = 4096
            };

            _testLaptop2 = new LaptopEntity()
            {
                Price = 1999.99M,
                Model = "Middle 2",
                RAM   = 32,
                SSD   = 512,
                HDD   = 1096
            };

            _testLaptop3 = new LaptopEntity()
            {
                Price = 299.99M,
                Model = "Cheap 2",
                RAM   = 8,
                SSD   = 0,
                HDD   = 512
            };

            _testToy1 = new ToyEntity()
            {
                Name   = "Lego My Mind",
                MinAge = 12,
                Price  = 500.00M
            };

            _testToy2 = new ToyEntity()
            {
                Name   = "Lego Star Wars",
                MinAge = 6,
                Price  = 120.00M
            };

            _testToy3 = new ToyEntity()
            {
                Name   = "Ball",
                MinAge = 2,
                Price  = 14.99M
            };
        }