コード例 #1
0
 public Laptop(LaptopModel laptopModel)
 {
     Name               = laptopModel.Name;
     Price              = laptopModel.Price;
     IsAvailable        = laptopModel.IsAvailable;
     Description        = laptopModel.Description;
     ProducerId         = laptopModel.ProducerId;
     ManufacturerId     = laptopModel.ManufacturerId;
     MaterialValue      = laptopModel.Material;
     ColorValue         = laptopModel.Color;
     AmountOfRAM        = laptopModel.AmountOfRAM;
     CPUFrequency       = laptopModel.CPUFrequency;
     Length             = laptopModel.Length;
     Height             = laptopModel.Height;
     Width              = laptopModel.Width;
     HaveFloppyDrives   = laptopModel.HaveFloppyDrives;
     SSDMemory          = laptopModel.SSDMemory;
     HardDiskMemory     = laptopModel.HardDiskMemory;
     CPUSocketTypeValue = laptopModel.CPUSocketType;
     NumberOfCores      = laptopModel.NumberOfCores;
     if (HaveFloppyDrives)
     {
         FloppyDrivesCount = laptopModel.FloppyDrivesCount;
     }
     Display = laptopModel.Display;
     if (laptopModel.UserId != null && laptopModel.UserId != new Guid())
     {
         UserId = laptopModel.UserId;
     }
 }
コード例 #2
0
        public IHttpActionResult PutLaptopModel(int id, LaptopModel laptopModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != laptopModel.ID)
            {
                return(BadRequest());
            }

            db.Entry(laptopModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LaptopModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
ファイル: CartTests.cs プロジェクト: bohdanzaiats999/Steve
        public void Can_Remove_Line()
        {
            // Arrange
            LaptopModel laptop1 = new LaptopModel {
                Id = 1, Name = "Laptop1"
            };
            LaptopModel laptop2 = new LaptopModel {
                Id = 2, Name = "Laptop2"
            };
            LaptopModel laptop3 = new LaptopModel {
                Id = 3, Name = "Laptop3"
            };

            var cart = new CartService();

            // Act
            cart.AddItem(laptop1, 1);
            cart.AddItem(laptop2, 4);
            cart.AddItem(laptop3, 2);
            cart.AddItem(laptop2, 1);

            cart.RemoveCart(laptop2);

            //Assert
            //    Assert.Equal(0, cart.GetCartLine().Where(c => c.Laptop == laptop2).Count());
            Assert.Equal(2, cart.GetCartLine().Count());
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,ImageUrl,Name,Description,Price,RamAndStorage,BatteryCapacity")] LaptopModel laptopModel)
        {
            if (id != laptopModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(laptopModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LaptopModelExists(laptopModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(string id, [Bind("ID,Product_Name,Img_Url,Price,Description")] LaptopModel laptopModel)
        {
            if (id != laptopModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(laptopModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LaptopModelExists(laptopModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
コード例 #6
0
        public List <LaptopModel> GetLaptops()
        {
            string        constring = ConfigurationManager.ConnectionStrings["BD_test"].ConnectionString;
            SqlConnection con       = new SqlConnection(constring);

            con.Open();
            Console.WriteLine("OK");
            List <LaptopModel> Laptop_ = new List <LaptopModel>();

            try
            {
                string sql = @"SELECT maker, Laptop.model, speed, ram, hd, price, screen " +
                             "FROM Laptop " +
                             "INNER JOIN Product " +
                             "ON Laptop.model=Product.model";

                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Connection = con;
                //cmd.CommandText = sql;
                SqlDataReader myReader;
                myReader = cmd.ExecuteReader();

                while (myReader.Read())
                {
                    int         makerId      = myReader.GetOrdinal("maker");
                    int         modelId      = myReader.GetOrdinal("model");
                    int         speedId      = myReader.GetOrdinal("speed");
                    int         ramId        = myReader.GetOrdinal("ram");
                    int         hdId         = myReader.GetOrdinal("hd");
                    int         priceId      = myReader.GetOrdinal("price");
                    int         screenId     = myReader.GetOrdinal("screen");
                    LaptopModel LaptopObject = new LaptopModel()
                    {
                        ProductMaker = (string)myReader[makerId],
                        Model        = (string)myReader[modelId],
                        CpuSpeed     = (Int16)myReader[speedId],
                        RamSize      = (Int16)myReader[ramId],
                        DiscSize     = (Single)myReader[hdId],
                        Price        = (decimal)myReader[priceId],
                        ScreenSize   = (byte)myReader[screenId]
                    };

                    Laptop_.Add(LaptopObject);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
            return(Laptop_);
        }
コード例 #7
0
        public IHttpActionResult GetLaptopModel(int id)
        {
            LaptopModel laptopModel = db.LaptopModels.Find(id);

            if (laptopModel == null)
            {
                return(NotFound());
            }

            return(Ok(laptopModel));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("ID,Product_Name,Img_Url,Price,Description")] LaptopModel laptopModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(laptopModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
コード例 #9
0
        public async Task <IActionResult> Create([Bind("ID,ImageUrl,Name,Description,Price,RamAndStorage,BatteryCapacity")] LaptopModel laptopModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(laptopModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(laptopModel));
        }
コード例 #10
0
        public IHttpActionResult PostLaptopModel(LaptopModel laptopModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.LaptopModels.Add(laptopModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = laptopModel.ID }, laptopModel));
        }
コード例 #11
0
 public IActionResult AddLaptop(LaptopModel laptopModel)
 {
     try
     {
         laptopService.AddLaptop(laptopModel);
         laptopService.Save();
     }
     catch (Exception e)
     {
         return(BadRequest(laptopModel + e.Message));
     }
     return(Ok(laptopModel));
 }
コード例 #12
0
        public IHttpActionResult DeleteLaptopModel(int id)
        {
            LaptopModel laptopModel = db.LaptopModels.Find(id);

            if (laptopModel == null)
            {
                return(NotFound());
            }

            db.LaptopModels.Remove(laptopModel);
            db.SaveChanges();

            return(Ok(laptopModel));
        }
コード例 #13
0
        public async Task <IHttpActionResult> ApproveLaptopModel(int id)
        {
            LaptopModel mobile = await db.LaptopModels.FindAsync(id);

            if (mobile == null)
            {
                return(NotFound());
            }
            if (mobile.status == "a")
            {
                return(BadRequest("Already approved"));
            }
            mobile.status = "a";
            await db.SaveChangesAsync();

            return(Ok("approved"));
        }
コード例 #14
0
ファイル: LaptopService.cs プロジェクト: huyqv-0507/lshop-be
        public void AddLaptop(LaptopModel laptopModel)
        {
            Laptop laptop = new Laptop
            {
                BrandId     = laptopModel.BrandId,
                ImageUrl    = laptopModel.ImageUrl,
                GraphicCard = laptopModel.GraphicCard,
                LaptopName  = laptopModel.LaptopName,
                Price       = laptopModel.Price,
                Quantity    = laptopModel.Quantity,
                Ram         = laptopModel.Ram,
                SeriesCPU   = laptopModel.SeriesCPU,
                Storage     = laptopModel.Storage,
                Weight      = laptopModel.Weight,
            };

            laptopRepository.Add(laptop);
        }
コード例 #15
0
        public void AddItem(LaptopModel laptop, int quantity)
        {
            CartModel cart = cartCollection
                             .Where(g => g.Laptop.Id == laptop.Id)
                             .FirstOrDefault();

            if (cart == null)
            {
                cartCollection.Add(new CartModel
                {
                    Laptop   = laptop,
                    Quantity = quantity
                });
            }
            else
            {
                cart.Quantity += quantity;
            }
        }
コード例 #16
0
        public async Task <int> AddLaptop(LaptopModel laptopModel, string email)
        {
            try
            {
                laptopModel.UserId = (await _context.Users.FirstOrDefaultAsync(user => user.Email == email)).Id;
                var laptop = new Laptop(laptopModel);
                var id     = await AddGoodData(laptopModel.ImageIds, laptop);
                await AddLaptopComputerDriveType(laptopModel.ComputerDriveTypes, id);

                await _context.Laptops.AddAsync(laptop);

                await _context.SaveChangesAsync();

                return(1);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #17
0
ファイル: CartTests.cs プロジェクト: bohdanzaiats999/Steve
        public void Calculate_Cart_Total()
        {
            // Arrange
            LaptopModel laptop1 = new LaptopModel {
                Id = 1, Name = "Laptop1", Price = 1
            };
            LaptopModel laptop2 = new LaptopModel {
                Id = 2, Name = "Laptop2", Price = 1
            };

            var cart = new CartService();

            // Act
            cart.AddItem(laptop1, 3);
            cart.AddItem(laptop2, 2);
            cart.AddItem(laptop1, 5);
            decimal result = cart.ComputeTotalValue();

            // Assert
            Assert.Equal(10, result);
        }
コード例 #18
0
ファイル: CartTests.cs プロジェクト: bohdanzaiats999/Steve
        public void Can_Clear_Content()
        {
            // Arrange
            LaptopModel laptop1 = new LaptopModel {
                Id = 1, Name = "Laptop1", Price = 100
            };
            LaptopModel laptop2 = new LaptopModel {
                Id = 2, Name = "Laptop2", Price = 55
            };

            var cart = new CartService();

            // Act
            cart.AddItem(laptop1, 1);
            cart.AddItem(laptop2, 1);
            cart.AddItem(laptop1, 5);
            cart.Clear();

            // Assert

            Assert.Equal(0, cart.GetCartLine().Count);
        }
コード例 #19
0
ファイル: CartTests.cs プロジェクト: bohdanzaiats999/Steve
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            //Arrange
            LaptopModel laptop1 = new LaptopModel {
                Id = 1, Name = "Laptop1"
            };
            LaptopModel laptop2 = new LaptopModel {
                Id = 2, Name = "Laptop2"
            };
            var cart = new CartService();

            //Act
            cart.AddItem(laptop1, 1);
            cart.AddItem(laptop2, 1);
            cart.AddItem(laptop1, 5);
            var result = cart.GetCartLine().OrderBy(c => c.Laptop.Id).ToList();

            //Assert
            Assert.Equal(2, result.Count);
            Assert.Equal(6, result[0].Quantity);
            Assert.Equal(1, result[1].Quantity);
        }
コード例 #20
0
ファイル: CartTests.cs プロジェクト: bohdanzaiats999/Steve
        public void Can_Add_New_Lines()
        {
            // Arrange
            LaptopModel laptop1 = new LaptopModel {
                Id = 1, Name = "Laptop1"
            };
            LaptopModel laptop2 = new LaptopModel {
                Id = 2, Name = "Laptop2"
            };

            var cart = new CartService();

            // Act
            cart.AddItem(laptop1, 1);
            cart.AddItem(laptop2, 1);

            var results = cart.GetCartLine();

            // Assert
            Assert.Equal(2, results.Count);
            Assert.Equal(1, results[0].Quantity);
            Assert.Equal(1, results[1].Quantity);
        }
コード例 #21
0
 public void RemoveCart(LaptopModel game)
 {
     cartCollection.RemoveAll(l => l.Laptop.Id == game.Id);
 }
コード例 #22
0
 public IActionResult AddLaptop(ProductModel p, LaptopModel spec)
 {
     return(new JsonResult(_productService.AddProductAsync <LaptopModel>(p, spec)));
 }
コード例 #23
0
        public async Task <bool> addNewBrandModel(string brand, string model, string category)
        {
            if (brand != null)
            {
                brand.Trim();
            }
            if (model != null)
            {
                model.Trim();
            }
            if (brand == "" || brand == "undefined" || brand == null)
            {
                return(true);
            }
            if (category == "Mobiles")
            {
                var isNew = db.Mobiles.Any(x => x.brand.Equals(brand));
                if (!isNew)
                {
                    Mobile mob = new Mobile();
                    mob.brand   = brand;
                    mob.addedBy = User.Identity.GetUserId();
                    mob.status  = "a";
                    mob.time    = DateTime.UtcNow;
                    db.Mobiles.Add(mob);
                    await db.SaveChangesAsync();

                    if (model != null && model != "" && model != "undefined")
                    {
                        MobileModel mod = new MobileModel();
                        mod.addedBy = User.Identity.GetUserId();
                        mod.brandId = mob.Id;
                        mod.status  = "a";
                        mod.time    = DateTime.UtcNow;
                        mod.model   = model;
                        db.MobileModels.Add(mod);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    var isNewModel = db.MobileModels.Any(x => x.model.Equals(model));
                    if (!isNewModel)
                    {
                        if (model != null && model != "" && model != "undefined")
                        {
                            var         brandId = db.Mobiles.First(x => x.brand.Equals(brand));
                            MobileModel mod     = new MobileModel();
                            mod.addedBy = User.Identity.GetUserId();
                            mod.brandId = brandId.Id;
                            mod.status  = "a";
                            mod.time    = DateTime.UtcNow;
                            mod.model   = model;
                            db.MobileModels.Add(mod);
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
            else if (category == "Laptops")
            {
                var isNew = db.LaptopBrands.Any(x => x.brand.Equals(brand));
                if (!isNew)
                {
                    LaptopBrand mob = new  LaptopBrand();
                    mob.brand   = brand;
                    mob.addedBy = User.Identity.GetUserId();
                    mob.status  = "a";
                    mob.time    = DateTime.UtcNow;
                    db.LaptopBrands.Add(mob);
                    await db.SaveChangesAsync();

                    if (model != null && model != "" && model != "undefined")
                    {
                        LaptopModel mod = new  LaptopModel();
                        mod.addedBy = User.Identity.GetUserId();
                        mod.brandId = mob.Id;
                        mod.status  = "a";
                        mod.time    = DateTime.UtcNow;
                        mod.model   = model;
                        db.LaptopModels.Add(mod);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    var isNewModel = db.LaptopModels.Any(x => x.model.Equals(model));
                    if (!isNewModel)
                    {
                        if (model != null && model != "" && model != "undefined")
                        {
                            LaptopModel mod = new  LaptopModel();
                            mod.addedBy = User.Identity.GetUserId();
                            mod.brandId = db.LaptopBrands.First(x => x.brand.Equals(brand)).Id;
                            mod.status  = "a";
                            mod.time    = DateTime.UtcNow;
                            mod.model   = model;
                            db.LaptopModels.Add(mod);
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
            else if (category == "Bikes")
            {
                var isNew = db.BikeBrands.Any(x => x.brand.Equals(brand));
                if (!isNew)
                {
                    BikeBrand mob = new  BikeBrand();
                    mob.brand   = brand;
                    mob.addedBy = User.Identity.GetUserId();
                    mob.status  = "a";
                    mob.time    = DateTime.UtcNow;
                    db.BikeBrands.Add(mob);
                    await db.SaveChangesAsync();

                    if (model != null && model != "" && model != "undefined")
                    {
                        BikeModel mod = new  BikeModel();
                        mod.addedBy = User.Identity.GetUserId();
                        mod.brandId = mob.Id;
                        mod.status  = "a";
                        mod.time    = DateTime.UtcNow;
                        mod.model   = model;
                        db.BikeModels.Add(mod);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    var isNewModel = db.BikeModels.Any(x => x.model.Equals(model));
                    if (!isNewModel)
                    {
                        if (model != null && model != "" && model != "undefined")
                        {
                            BikeModel mod = new  BikeModel();
                            mod.addedBy = User.Identity.GetUserId();
                            mod.brandId = db.BikeBrands.First(x => x.brand.Equals(brand)).Id;
                            mod.status  = "a";
                            mod.time    = DateTime.UtcNow;
                            mod.model   = model;
                            db.BikeModels.Add(mod);
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
            else if (category == "Cars")
            {
                var isNew = db.CarBrands.Any(x => x.brand.Equals(brand));
                if (!isNew)
                {
                    CarBrand mob = new  CarBrand();
                    mob.brand   = brand;
                    mob.addedBy = User.Identity.GetUserId();
                    mob.status  = "a";
                    mob.time    = DateTime.UtcNow;
                    db.CarBrands.Add(mob);
                    await db.SaveChangesAsync();

                    if (model != null && model != "" && model != "undefined")
                    {
                        CarModel mod = new  CarModel();
                        mod.addedBy = User.Identity.GetUserId();
                        mod.brandId = mob.Id;
                        mod.status  = "a";
                        mod.time    = DateTime.UtcNow;
                        mod.model   = model;
                        db.CarModels.Add(mod);
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    var isNewModel = db.CarModels.Any(x => x.model.Equals(model));
                    if (!isNewModel)
                    {
                        if (model != null && model != "" && model != "undefined")
                        {
                            CarModel mod = new  CarModel();
                            mod.addedBy = User.Identity.GetUserId();
                            mod.brandId = db.CarBrands.First(x => x.brand.Equals(brand)).Id;
                            mod.status  = "a";
                            mod.time    = DateTime.UtcNow;
                            mod.model   = model;
                            db.CarModels.Add(mod);
                            await db.SaveChangesAsync();
                        }
                    }
                }
            }
            return(true);
        }
コード例 #24
0
 public async Task <int> AddLaptop([FromBody] LaptopModel laptopModel)
 {
     return(await _goodsCreator.AddLaptop(laptopModel, User.Identity.Name));
 }