コード例 #1
0
        public void Delete(RepoBuyCar id)
        {
            BuyCar obj = db.BuyCars.FirstOrDefault(x => x.CarId == id.CarId && x.BuyerId == id.BuyerId);

            db.BuyCars.Remove(obj);
            db.SaveChanges();
        }
コード例 #2
0
ファイル: DataTest.cs プロジェクト: pawrob/TPR_PB_RM
        public void GetBillTest()
        {
            Car Car1 = new Car("Alfa Romeo", "Brera", "Italia Independent", 210, "Matte Grey", VehicleType.Coupe, FuelType.Diesel, Transmission.Manual);

            WarehouseItem wi1 = new WarehouseItem(Car1, 10000, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"));
            BuyCar        b1  = new BuyCar(wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"), Convert.ToDateTime("5.11.2020"));

            dataRepository.AddBill(b1);
            Assert.IsTrue(dataRepository.GetBill(b1.Id) == b1);
        }
コード例 #3
0
ファイル: Convert.cs プロジェクト: AntonNagula/Shop
 public static RepoBuyCar FromBuyCarToRepoBuyCar(this BuyCar item)
 {
     return(new RepoBuyCar
     {
         BuyerId = item.BuyerId,
         Buyer = item.Buyer.FromBuyerToRepoBuyer(),
         Car = item.Car.FromCarToRepoCar(),
         CarId = item.CarId
     });
 }
コード例 #4
0
ファイル: DataRepository.cs プロジェクト: pawrob/TPR_PB_RM
        public void UpdateBill(Guid id, BuyCar bill)
        {
            BuyCar foundBill = dataContext.BoughtCars.First(f => f.Id.Equals(id));

            if (foundBill == null)
            {
                throw new ArgumentException($"Bill with {id} id doesn't exist");
            }
            dataContext.BoughtCars[dataContext.BoughtCars.IndexOf(foundBill)] = bill;
        }
コード例 #5
0
ファイル: DataRepository.cs プロジェクト: pawrob/TPR_PB_RM
 public void DeleteBill(BuyCar bill)
 {
     if (dataContext.BoughtCars.Contains(bill))
     {
         dataContext.BoughtCars.Remove(bill);
     }
     else
     {
         throw new ArgumentException($"There isn't bill with {bill.Id} id in warehouse");
     }
 }
コード例 #6
0
        public void UpdateBillTest()
        {
            Assert.AreEqual(0, dataService.GetAllBills().Count());

            dataService.AddCar("Skoda", "Fabia", "Style", 210, "Silver Metalic", VehicleType.Small_car, FuelType.Petrol, Transmission.Manual);
            dataService.AddWarehouseItem(dataService.GetAllCars().First(), 10000);
            dataService.AddBill(dataService.GetAllWarehouseItems().First());
            BuyCar b2 = new BuyCar(dataService.GetAllWarehouseItems().First(), new Guid(), DateTime.Now);

            dataService.updateBill(dataService.GetAllBills().First().Id, b2);

            Assert.AreEqual(dataService.GetAllBills().First(), b2);
        }
コード例 #7
0
 public ActionResult Buy_Car(string IdMark, string IdModel, string IdModification, string Mark, string Model, string Modification, decimal Price)
 {
     {
         BuyCar buycar = new BuyCar();
         buycar.Mark           = Mark;
         buycar.Model          = Model;
         buycar.Modification   = Modification;
         buycar.IdMark         = IdMark;
         buycar.IdModel        = IdModel;
         buycar.IdModification = IdModification;
         buycar.Price          = Price;
         ViewBag.buycar        = buycar;
         return(View());
     }
 }
コード例 #8
0
ファイル: DataRepository.cs プロジェクト: pawrob/TPR_PB_RM
 public void AddBill(BuyCar bill)
 {
     try
     {
         dataContext.BoughtCars.Add(bill);
     }
     catch (ArgumentNullException e)
     {
         throw new ArgumentNullException($"Bill with Id {bill.Id} do not exist.", e);
     }
     catch (ArgumentException e)
     {
         throw new ArgumentException($"Bill with Id {bill.Id} already exists.", e);
     }
 }
コード例 #9
0
ファイル: DataTest.cs プロジェクト: pawrob/TPR_PB_RM
        public void UpdateBillTest()
        {
            Car Car1 = new Car("Alfa Romeo", "Brera", "Italia Independent", 210, "Matte Grey", VehicleType.Coupe, FuelType.Diesel, Transmission.Manual);

            WarehouseItem wi1 = new WarehouseItem(Car1, 10000, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"));
            BuyCar        b1  = new BuyCar(wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"), Convert.ToDateTime("5.11.2020"));

            dataRepository.AddBill(b1);
            Car           Car2 = new Car("Skoda", "Fabia", "Style", 210, "Silver Metalic", VehicleType.Small_car, FuelType.Petrol, Transmission.Manual);
            WarehouseItem wi2  = new WarehouseItem(Car2, 210000, Guid.Parse("2273ec6b-7c26-4bce-8ec0-00a2773d108a"));
            BuyCar        b2   = new BuyCar(wi2, Guid.Parse("bef406e7-61b5-4a14-86b7-d20af86cb752"), Convert.ToDateTime("8.11.2020"));

            dataRepository.UpdateBill(b1.Id, b2);

            Assert.AreEqual(b2, dataRepository.GetAllBillesOfSale().First());
        }
コード例 #10
0
        public ActionResult ADDBuyCart(string pic, string name, int comid, int uid, decimal price)
        {
            Models.BuyCar buyCar = new BuyCar();
            buyCar.BpicUrl1 = pic;
            buyCar.comName  = name;
            buyCar.Bprice   = price;
            buyCar.Comid    = comid;
            buyCar.Uid      = uid;
            db.BuyCar.Add(buyCar);
            int i = db.SaveChanges();

            if (i == 0)
            {
                return(Content("<script>alert('添加失败~');</script>"));
            }
            return(Content("<script>alert('添加购物车成功~');window.location.href='/Index/index';</script>"));
        }
コード例 #11
0
ファイル: DataManualFiller.cs プロジェクト: pawrob/TPR_PB_RM
        public void InsertData(DataContext dataContext)
        {
            Client c1   = new Client("John", "Doe", 000000000, Guid.NewGuid());
            Client c2   = new Client("Jack", "Karabinczyk", 213721151, Guid.NewGuid());
            Client c3   = new Client("Peter", "Parker", 123456789, Guid.NewGuid());
            Car    Car2 = new Car("Skoda", "Fabia", "Style", 210, "Silver Metalic", VehicleType.Small_car, FuelType.Petrol, Transmission.Manual);
            Car    Car1 = new Car("Alfa Romeo", "Brera", "Italia Independent", 210, "Matte Grey", VehicleType.Coupe, FuelType.Diesel, Transmission.Manual);

            WarehouseItem wi1 = new WarehouseItem(Car1, 10000, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b80b"));
            SellCar       f1  = new SellCar(c1, wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b90b"), Convert.ToDateTime("5.11.2020"));
            BuyCar        b1  = new BuyCar(wi1, Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b91b"), Convert.ToDateTime("5.11.2020"));

            dataContext.Clients.Add(c1);
            dataContext.Clients.Add(c2);
            dataContext.Clients.Add(c3);
            dataContext.Cars.Add(Guid.Parse("594e4c41-7e20-432c-9773-085d75e9b80d"), Car1);
            dataContext.Cars.Add(Guid.Parse("694e4c41-7e20-432c-9773-085d75e9b80d"), Car2);
            dataContext.WarehouseItems.Add(wi1);
            dataContext.BoughtCars.Add(b1);
            dataContext.SoldCars.Add(f1);
        }
コード例 #12
0
        public async Task <bool> Buy(BuyCar buyCar, string username)
        {
            var user = await this.context.Users.SingleOrDefaultAsync(u => u.UserName == username);

            var car = await this.context.Cars.SingleOrDefaultAsync(c => c.Id == buyCar.CarId);

            if (user == null || car == null || user.Balance < car.Price)
            {
                return(false);
            }

            buyCar.User     = user;
            buyCar.BoughtOn = DateTime.Now;
            buyCar.Price    = car.Price;

            user.Balance -= car.Price;

            this.context.BoughtCars.Add(buyCar);

            await this.context.SaveChangesAsync();

            return(true);
        }
コード例 #13
0
 public void Test2()
 {
     int[] r = new int[] { 0, 4000 };
     Assert.AreEqual(r, BuyCar.nbMonths(12000, 8000, 1000, 1.5));
 }
コード例 #14
0
 public void Test1()
 {
     int[] r = new int[] { 6, 766 };
     Assert.AreEqual(r, BuyCar.nbMonths(2000, 8000, 1000, 1.5));
 }
コード例 #15
0
 public void updateBill(Guid id, BuyCar bill)
 {
     dataRepository.UpdateBill(id, bill);
 }
コード例 #16
0
 public void DeleteBill(BuyCar bill)
 {
     dataRepository.DeleteBill(bill);
 }