コード例 #1
0
ファイル: Service.cs プロジェクト: AntonNagula/Auto
        //
        public bool Buy(DomainBuyCar item)
        {
            DomainCar car = Cars.FirstOrDefault(x => x.Id == item.CarId);

            item.Car   = car;
            item.Buyer = Buyers.FirstOrDefault(x => x.Id == item.BuyerId);
            BuyCars.Add(item);
            _Repositories.Cars.Update(car.FromDomainCarToRepoCar());
            _Repositories.BuyCars.Create(item.FromDomainBuyCarToRepoBuyCar());
            return(true);
        }
コード例 #2
0
ファイル: Mapping.cs プロジェクト: AntonNagula/Auto
 public static AppCar FromDomainCarToRepoCar(this DomainCar item)
 {
     return(new AppCar
     {
         Id = item.Id,
         Name = item.Name,
         CarBrand = item.CarBrand,
         Price = item.Price,
         ExtencionName = item.ExtencionName,
         Info = item.Info,
         image = item.image,
         OwnerId = item.OwnerId,
         BrandId = item.BrandId,
     });
 }
コード例 #3
0
        public void Delete_Car(int id)
        {
            //List<DomainBuyCar> list = _Repositories.BuyCars.GetById(id).Select(x=>x.FromRepoBuyCarToDomainBuyCar()).ToList();
            //if (list.Count == 0)
            //    _Repositories.Cars.Delete(id);
            //else
            //{
            //    DomainCar car = _Repositories.Cars.Get(id).FromRepoCarToDomainCar();
            //    _Repositories.Cars.Update(car.FromDomainCarToRepoCar());
            //}

            DomainCar car = Cars.Find(x => x.Id == id);

            Cars.Remove(car);
            _Repositories.Cars.Delete(id);
        }
コード例 #4
0
        public void Update_Car(DomainCar item)
        {
            if (item.BrandId == 0)
            {
                //int size = Brands.Count;
                //int BrandId = Brands[size - 1].Id;
                //item.BrandId = BrandId+1;
                int BrandId = Brands.Find(x => x.BrandName == item.CarBrand).Id;
                item.BrandId = BrandId;
            }
            _Repositories.Cars.Update(item.FromDomainCarToRepoCar());
            DomainCar current = Cars.Find(x => x.Id == item.Id);
            int       index   = Cars.IndexOf(current);

            Cars[index] = item;
        }
コード例 #5
0
        //
        public bool Buy(DomainBuyCar item)
        {
            DomainCar car = Cars.FirstOrDefault(x => x.Id == item.CarId);

            item.Car   = car;
            item.Buyer = Buyers.FirstOrDefault(x => x.Id == item.BuyerId);
            DomainBuyCar obj = BuyCars.FirstOrDefault(x => x.CarId == item.CarId && x.BuyerId == item.BuyerId);

            if (obj == null)
            {
                BuyCars.Add(item);
                _Repositories.BuyCars.Create(item.FromDomainBuyCarToRepoBuyCar());
                return(true);
            }

            return(false);
        }
コード例 #6
0
 public ActionResult Create(HttpPostedFileBase upload, AppCar ViewCar)
 {
     if (upload != null)
     {
         string fileName      = Path.GetFileName(upload.FileName);
         string ext           = Path.GetExtension(fileName);
         string ExtencionName = ViewCar.Name + ext;
         upload.SaveAs(Server.MapPath("~/Files/" + ViewCar.Name + ext));
         byte[] avatar = new byte[upload.ContentLength];
         upload.InputStream.Read(avatar, 0, upload.ContentLength);
         DomainCar car  = new DomainCar(ViewCar.Name, ViewCar.CarBrand, ViewCar.BrandId, ViewCar.Price, ExtencionName, ViewCar.Info, avatar);
         string    mail = HttpContext.User.Identity.Name;
         car.OwnerId = unit.GetBuyer(mail).Id;
         unit.Create_Car(car);
     }
     ViewBag.Message = "Авто занесено в базу данных";
     return(View("~/Views/Buyer/Buy.cshtml"));
 }
コード例 #7
0
 //
 public void Create_Car(DomainCar item)
 {
     if (item.BrandId == 0)
     {
         int size = 1 + GetAllBrands().ToList().Count;
         item.BrandId = size;
         DomainBrands brand = new DomainBrands {
             BrandName = item.CarBrand
         };
         Brands.Add(brand);
         _Repositories.Brands.Create(brand.FromDomainBrandToRepoBrand());
     }
     else
     {
         item.CarBrand = Brands.FirstOrDefault(x => x.Id == item.BrandId).BrandName;
     }
     Cars.Add(item);
     _Repositories.Cars.Create(item.FromDomainCarToRepoCar());
 }
コード例 #8
0
 public static RepoCar FromDomainCarToRepoCar(this DomainCar item)
 {
     if (item == null)
     {
         return(null);
     }
     return(new RepoCar
     {
         Id = item.Id,
         Name = item.Name,
         CarBrand = item.CarBrand,
         Price = item.Price,
         ExtencionName = item.ExtencionName,
         Info = item.Info,
         image = item.image,
         OwnerId = item.OwnerId,
         BrandId = item.BrandId,
         //BuyCars = item.BuyCars.Select(x => x.FromDomainBuyCarToRepoBuyCar()).ToList(),
     });
 }
コード例 #9
0
ファイル: Service.cs プロジェクト: AntonNagula/Auto
 public void Update_Car(DomainCar item)
 {
     _Repositories.Cars.Update(item.FromDomainCarToRepoCar());
 }