Esempio n. 1
0
        private void LoadBrand()
        {
            _file = new FileInfo(Application.StartupPath + @"\\Vehicle.xlsx");

            using (var package = new ExcelPackage(_file))
            {
                var workbook = package.Workbook;

                using (var tx = NHibernateSessionManager.GetLocalSession().BeginTransaction())
                {
                    var ws = workbook.Worksheets[@"Brand"];

                    for (var i = 1; i < ws.Dimension.End.Row + 1; i++)
                    {
                        var newBrand = new VehicleBrand(
                            ws.Cells[i, 1].Value.ToString(),
                            ws.Cells[i, 2].Value.ToString()
                            );

                        _vehicleBrandRepository.Insert(newBrand);
                    }

                    tx.Commit();
                }
            }
        }
Esempio n. 2
0
        public IList <VehicleModel> GetAllInBrand(VehicleBrand brand)
        {
            var criteria = DetachedCriteria.For <VehicleModel>()
                           .Add(Restrictions.Eq(@"Brand", brand));

            return(_repo.FindAll(criteria));
        }
Esempio n. 3
0
 public VehicleModel(string code, string name, VehicleBrand brand, VehicleSize size, VehicleType type) : base(code)
 {
     _name  = name;
     _brand = brand;
     _size  = size;
     _type  = type;
 }
        private bool GetIds(string sLine, out int parentId, out int startId, out VehicleBrand parentBrand)
        {
            bool bRet  = false;
            int  index = sLine.IndexOf(",");

            parentBrand = null;
            parentId    = -1; startId = -1;
            if (index > 0 && sLine.LastIndexOf(",") == index)
            {
                string[] ids = sLine.Split(",".ToCharArray());
                if (int.TryParse(ids[0], out parentId) && int.TryParse(ids[1], out startId))
                {
                    foreach (KeyValuePair <int, Tuple <int, VehicleBrand> > kv in m_DTBrand2Range)
                    {
                        if (startId >= kv.Key && startId <= kv.Value.Item1)
                        {
                            parentId    = (int)kv.Value.Item2.Id;
                            parentBrand = kv.Value.Item2;
                            bRet        = true;
                            break;
                        }
                    }
                }
            }
            return(bRet);
        }
Esempio n. 5
0
 public async Task <IActionResult> Create(CreateVehicleBrandViewModel model)
 {
     if (ModelState.IsValid)
     {
         VehicleBrand newBrand = new VehicleBrand()
         {
             BrandId   = Guid.NewGuid().ToString(),
             BrandName = model.BrandName
         };
         if (await _brandServices.CreateBrand(newBrand))
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-success", Title = "Thành công", Message = "Tạo nhãn hiệu mới thành công"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         }
         else
         {
             var userMessage = new MessageVM()
             {
                 CssClassName = "alert alert-danger", Title = "Không thành công", Message = "Đã có lỗi khi thao tác, xin mời thử lại"
             };
             TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage);
         };
     }
     return(RedirectToAction(actionName: "Index"));
 }
Esempio n. 6
0
        public static int Delete(VehicleBrand vbm)
        {
            if (vbm == null)
            {
                return(-2);
            }
            if (vbm.Id < 0)
            {
                return(-3);
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);

            XmlNode node = xmlDoc.SelectSingleNode($"//VehicleBrands//VehicleBrand[@id='{vbm.Id}']");

            if (node != null)
            {
                XmlNode root = xmlDoc.SelectSingleNode("VehicleBrands");
                root?.RemoveChild(node);
            }
            else
            {
                return(-1);
            }

            xmlDoc.Save(filename);

            return(0);
        }
Esempio n. 7
0
        public static int Update(VehicleBrand vbm)
        {
            if (vbm == null)
            {
                return(-2);
            }
            if (vbm.Id < 0)
            {
                return(-3);
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);

            XmlNode node = xmlDoc.SelectSingleNode($"//VehicleBrands//VehicleBrand[@id='{vbm.Id}']");

            XmlNode brandName = node?.SelectSingleNode("BrandName");
            XmlNode logoUrl   = node?.SelectSingleNode("LogoUrl");


            if (brandName == null || logoUrl == null)
            {
                return(-1);
            }
            brandName.InnerText = vbm.BrandName;
            logoUrl.InnerText   = vbm.LogoUrl;

            xmlDoc.Save(filename);

            return(0);
        }
        private Response CheckToAddOrUpdate(VehicleBrand vehicleBrand)
        {
            bool isUpdate = vehicleBrand.Id > 0;

            int sameNumberOfRecords = (from b in Context.VehicleBrand
                                       where b.Name == vehicleBrand.Name && b.Id != vehicleBrand.Id
                                       select b
                                       ).Count();

            if (sameNumberOfRecords > 0)
            {
                return(Response.Fail($"{vehicleBrand.Name} markası sistemde zaten kayıtlıdır."));
            }
            if (isUpdate)
            {
                int numberOfModels = Context.VehicleModel.Where(m => m.VehicleBrandId == vehicleBrand.Id).Count();
                if (numberOfModels > 0)
                {
                    return(Response.Fail($"{vehicleBrand.Name} markasına ait {numberOfModels} adet model olduğu için bu kayıt silinemez."));
                }
            }



            return(Response.Success());
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit(int id, [Bind("VehicleBrandID,VehicleBrandName,VehicleBrandDescription,VehicleBrandIntroductionDate")] VehicleBrand vehicleBrand)
        {
            if (id != vehicleBrand.VehicleBrandID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleBrand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleBrandExists(vehicleBrand.VehicleBrandID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleBrand));
        }
Esempio n. 10
0
        public void Seed()
        {
            if (_context.VehicleBrand.Any() || _context.VehicleType.Any() || _context.User.Any())
            {
                return;
            }
            VehicleBrand vb1 = new VehicleBrand("Toyota");
            VehicleBrand vb2 = new VehicleBrand("Honda");
            VehicleBrand vb3 = new VehicleBrand("Nissan");
            VehicleBrand vb4 = new VehicleBrand("Ford");
            VehicleBrand vb5 = new VehicleBrand("BMW");
            VehicleBrand vb6 = new VehicleBrand("Suzuki");

            VehicleType vt1 = new VehicleType("Hatchback");
            VehicleType vt2 = new VehicleType("Sedan");
            VehicleType vt3 = new VehicleType("Pickup");
            VehicleType vt4 = new VehicleType("Sport");
            VehicleType vt5 = new VehicleType("Van");

            User user = new User("Dacioso", "admin", "123".GetHashCode().ToString(), true);

            _context.VehicleBrand.AddRange(vb1, vb2, vb3, vb4, vb5, vb6);
            _context.VehicleType.AddRange(vt1, vt2, vt3, vt4, vt5);
            _context.User.Add(user);

            _context.SaveChanges();
        }
        public async void GetVehicleBrands()
        {
            try
            {
                var result = Dbcontext.GetCompanyVehicleBrands(Application.Current.Properties["UN"].ToString(),
                                                               Application.Current.Properties["PW"].ToString(), Application.Current.Properties["Ucid"].ToString(),
                                                               Convert.ToInt32(Application.Current.Properties["CompanyId"].ToString()));
                AllVehicleBrands = new ObservableCollection <VehicleBrand>();
                VehicleBrand brand;


                if (result != null)
                {
                    if (result.Length > 0)
                    {
                        foreach (var data in result)
                        {
                            brand      = new VehicleBrand();
                            brand.Id   = data.Id;
                            brand.Name = data.Name;

                            AllVehicleBrands.Add(brand);
                        }
                    }
                }
                GetErrorCodes();
            }
            catch (Exception e)
            {
                IsBusy = false;
                await Application.Current.MainPage.DisplayAlert("Fel", e.Message, "Stäng");
            }
        }
Esempio n. 12
0
 public VehicleModel(string code, string name, VehicleBrand brand, VehicleSize size, VehicleType type)
     : base(code)
 {
     _name = name;
     _brand = brand;
     _size = size;
     _type = type;
 }
        public ActionResult DeleteConfirmed(int id)
        {
            VehicleBrand vehicleBrand = VehicleBrands.GetByID(id);

            VehicleBrands.Delete(vehicleBrand);
            VehicleBrands.Commit();
            return(RedirectToAction("Index"));
        }
Esempio n. 14
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            VehicleBrand vehicleBrand = db.VehicleBrands.Find(id);

            db.VehicleBrands.Remove(vehicleBrand);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 15
0
 public override bool Equals(object obj)
 {
     return(obj is VehicleDetail detail &&
            VehicleType.Equals(detail?.VehicleType) &&
            VehicleBrand.Equals(detail?.VehicleBrand) &&
            VehicleModel.Equals(detail?.VehicleModel) &&
            StateNumber.Equals(detail?.StateNumber));
 }
Esempio n. 16
0
        protected virtual void OnFormTransactionSuccess(VehicleBrand brand, bool status)
        {
            var handler = FormTransactionSuccess;

            if (handler != null)
            {
                handler(this, new FormTransactionSuccessArgs <VehicleBrand>(brand, true));
            }
        }
Esempio n. 17
0
        protected virtual void OnFormTransactionSuccess(VehicleBrand brand, bool status)
        {
            var handler = FormTransactionSuccess;

            if (handler != null)
            {
                handler(this, new FormTransactionSuccessArgs<VehicleBrand>(brand, true));
            }
        }
Esempio n. 18
0
 void FillVehicleModifications(VehicleBrand vehicleBrand)
 {
     vehicleModifications.Clear();
     foreach (VehicleModification vehicle in storeService.VehicleService.GetModifications(vehicleBrand))
     {
         vehicleModifications.Add(vehicle);
     }
     NotifyPropertyChanged(nameof(VehicleModifications));
 }
 public void FillVehicleModifications(VehicleBrand vehicleBrand)
 {
     vehicleModifications.Clear();
     foreach (VehicleModification vehicleModification in storeService.VehicleService.GetModifications(vehicleBrand))
     {
         vehicleModifications.Add(vehicleModification);
     }
     VehicleModificationComboboxes.FillVehicleModificationComboboxes(vehicleModifications);
 }
Esempio n. 20
0
        private void cboBrand_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboBrand.SelectedItem != null)
            {
                VehicleBrand selectedBrand = _vehicleBrands.First(x => x.Name == cboBrand.SelectedItem.ToString());

                _presenter.GetModel(selectedBrand);
            }
        }
        public VehicleBrandInfo GetVehicleBrandInfo(int id)
        {
            VehicleBrand     brand   = service.GetBrand(id);
            VehicleBrandInfo subinfo = new VehicleBrandInfo();

            if (brand != null)
            {
                subinfo = new VehicleBrandInfo()
                {
                    ID       = (int)brand.Id,
                    ParentId = (int)(brand.ParentId ?? 0),
                    Name     = brand.Name,
                    Logo     = null,
                    Back     = brand.Back,
                    Front    = brand.Front,
                };
                //if (brand.Logo != null)
                //{
                //    System.IO.MemoryStream ms = new System.IO.MemoryStream(brand.Logo);
                //    try
                //    {
                //        subinfo.Logo = System.Drawing.Image.FromStream(ms);
                //    }
                //    catch (ArgumentException aex)
                //    {
                //        subinfo.Logo = null;
                //    }
                //}

                //if (brand.Front != null)
                //{
                //    System.IO.MemoryStream ms = new System.IO.MemoryStream(brand.Front);
                //    try
                //    {
                //        subinfo.Front = System.Drawing.Image.FromStream(ms);
                //    }
                //    catch (ArgumentException aex)
                //    {
                //        subinfo.Front = null;
                //    }
                //}
                //if (brand.Back != null)
                //{
                //    System.IO.MemoryStream ms = new System.IO.MemoryStream(brand.Back);
                //    try
                //    {
                //        subinfo.Back = System.Drawing.Image.FromStream(ms);
                //    }
                //    catch (ArgumentException aex)
                //    {
                //        subinfo.Back = null;
                //    }
                //}
            }

            return(subinfo);
        }
Esempio n. 22
0
 public ActionResult Edit([Bind(Include = "Id,Descripcion,FechaAlta,Enable")] VehicleBrand vehicleBrand)
 {
     if (ModelState.IsValid)
     {
         db.Entry(vehicleBrand).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(vehicleBrand));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Image,Description")] VehicleBrand vehicleBrand)
 {
     if (ModelState.IsValid)
     {
         VehicleBrands.Update(vehicleBrand);
         VehicleBrands.Commit();
         return(RedirectToAction("Index"));
     }
     return(View(vehicleBrand));
 }
Esempio n. 24
0
        public Response CheckToDelete(VehicleBrand vehicleBrand)
        {
            int numberOfModels = Context.VehicleModel.Where(m => m.VehicleBrandId == vehicleBrand.Id).Count();

            if (numberOfModels > 0)
            {
                return(Response.Fail($"{vehicleBrand.Name} markasına ait {numberOfModels} adet model olduğu için bu kayıt silinemez."));
            }
            return(Response.Success());
        }
Esempio n. 25
0
        private Response CheckToDelete(VehicleBrand vehicleBrand)
        {
            int numberOfModels = Context.VehicleModel.Where(m => m.VehicleBrandId == vehicleBrand.Id).Count();

            if (numberOfModels > 0)
            {
                return(Response.Fail($"{vehicleBrand.Name} markasına ait {numberOfModels} adet model olduğundan bu marka silinemiyor"));
            }
            return(Response.Succes());
        }
Esempio n. 26
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (VehicleType != null ? VehicleType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (VehicleBrand != null ? VehicleBrand.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (VehicleModel != null ? VehicleModel.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StateNumber != null ? StateNumber.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 27
0
        private async Task SaveEntity()
        {
            var VehicleBrand = new VehicleBrand()
            {
                Description = txtDescription.Text.Trim(),
                Status      = (StatusEnum)cbStatus.SelectedItem
            };
            await _VehicleBrand.Add(VehicleBrand);

            await _VehicleBrand.SaveAsync();
        }
Esempio n. 28
0
        public async Task <IActionResult> Create([Bind("VehicleBrandID,VehicleBrandName,VehicleBrandDescription,VehicleBrandIntroductionDate")] VehicleBrand vehicleBrand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleBrand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleBrand));
        }
Esempio n. 29
0
        public ActionResult Create([Bind(Include = "Id,Descripcion,FechaAlta,Enable")] VehicleBrand vehicleBrand)
        {
            if (ModelState.IsValid)
            {
                db.VehicleBrands.Add(vehicleBrand);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(vehicleBrand));
        }
Esempio n. 30
0
        public VehicleModel Save(string code, string name, VehicleBrand brand, VehicleSize size, VehicleType type)
        {
            VehicleModel newModel = null;
            var session = NHibernateSessionManager.GetLocalSession();

            session.DoTransactional(sess =>
                {
                    newModel = _modelRepo.Insert(new VehicleModel(code, name, brand, size, type));
                });

            return newModel;
        }
Esempio n. 31
0
        public async Task <ActionResult> BrandCreate([Bind(Include = "VehicleBrandId,BrandName,IsActive")] VehicleBrand brand)
        {
            if (ModelState.IsValid)
            {
                db.vehicleBrands.Add(brand);
                await db.SaveChangesAsync();

                return(Json(new { success = true }));
            }

            return(PartialView("_BrandCreate", brand));
        }
Esempio n. 32
0
        public Response Add(VehicleBrand vehicleBrand)
        {
            var checkadd = CheckToAddOrUpdate(vehicleBrand);

            if (!checkadd.IsSuccess)
            {
                return(checkadd);
            }
            Context.VehicleBrand.Add(vehicleBrand);
            Context.SaveChanges();
            return(Response.Succes($"{vehicleBrand.Name} markası başarı ile kayıt edildi"));
        }
Esempio n. 33
0
        public VehicleModel Save(string code, string name, VehicleBrand brand, VehicleSize size, VehicleType type)
        {
            VehicleModel newModel = null;
            var          session  = NHibernateSessionManager.GetLocalSession();

            session.DoTransactional(sess =>
            {
                newModel = _modelRepo.Insert(new VehicleModel(code, name, brand, size, type));
            });

            return(newModel);
        }
Esempio n. 34
0
        public void CanAddContinuously()
        {
            using (var session = NHibernateSessionManager.GetLocalSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    var brand = new VehicleBrand("BRND", "new");

                    session.Save(brand);

                    tx.Commit();
                }

                using (var tx = session.BeginTransaction())
                {
                    var brand = new VehicleBrand("BRNDA", "new");

                    session.Save(brand);

                    tx.Commit();
                }
            }
        }
Esempio n. 35
0
 public void GetModel(VehicleBrand selectedBrand)
 {
     _form.Models = _modelRepo.GetAllInBrand(selectedBrand);
 }
Esempio n. 36
0
 public void GetModel(VehicleBrand brand)
 {
     _view.VehicleModels = _modelRepo.GetAllInBrand(brand);
 }
        private void LoadBrand()
        {
            _file = new FileInfo(Application.StartupPath + @"\\Vehicle.xlsx");

            using (var package = new ExcelPackage(_file))
            {
                var workbook = package.Workbook;

                using (var tx = NHibernateSessionManager.GetLocalSession().BeginTransaction())
                {
                    var ws = workbook.Worksheets[@"Brand"];

                    for (var i = 1; i < ws.Dimension.End.Row + 1; i++)
                    {
                        var newBrand = new VehicleBrand(
                            ws.Cells[i, 1].Value.ToString(),
                            ws.Cells[i, 2].Value.ToString()
                        );

                        _vehicleBrandRepository.Insert(newBrand);
                    }

                    tx.Commit();
                }
            }
        }
Esempio n. 38
0
        public void AdvancedSearchAds_CarAds_CarProperties_ReturnCarAd()
        {
            ISessionFactory sessionFactory = NhibernateHelper.SessionFactory;
            Repository repo = new Repository(sessionFactory);
            SearchRepository adRepo = new SearchRepository(sessionFactory);

            using (ITransaction transaction = sessionFactory.GetCurrentSession().BeginTransaction())
            {
                // Given
                #region test data
                Province p1 = new Province
                {
                    Label = "p1"
                };

                User u = new User
                {
                    Email = "*****@*****.**",
                    Password = "******"
                };
                repo.Save<User>(u);

                City c = new City
                {
                    Label = "city",
                    LabelUrlPart = "city"
                };
                p1.AddCity(c);

                Category cat = new Category
                {
                    Label = "Auto",
                    LabelUrlPart = "Auto"
                };

                CarFuel fuel = new CarFuel
                {
                    Label = "Diesel"
                };

                VehicleBrand brand = new VehicleBrand
                {
                    Label = "Aveo"
                };

                SearchAdCache a = new SearchAdCache
                {
                    AdId = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                CarAd car = new CarAd
                {
                    Id = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    Year = 2011,
                    Kilometers = 10000,
                    IsAutomatic = true,
                    Fuel = fuel,
                    Brand = brand,
                    CreatedBy = u
                };

                repo.Save(brand);
                repo.Save(fuel);
                repo.Save(p1);
                repo.Save(c);
                repo.Save(cat);
                repo.Save(u);
                repo.Save(car);
                repo.Save(a);

                SearchAdCache a2 = new SearchAdCache
                {
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat
                };

                CarAd car2 = new CarAd
                {
                    Id = 1,
                    Title = "aveo",
                    Body = "aveo sport 1.2 16s",
                    City = c,
                    CreationDate = new DateTime(2012, 01, 16, 23, 52, 18),
                    Category = cat,
                    Year = 2001,
                    Kilometers = 95000,
                    Brand = brand,
                    CreatedBy = u
                };
                repo.Save(car2);
                repo.Save(a2);

                repo.Flush();

                #endregion

                AdSearchParameters param = new AdSearchParameters
                {
                    AndSearchStrings = new String[] { "aveo" },
                    MinKm = 0,
                    MaxKm = 11000,
                    MinYear = 2000,
                    MaxYear = 2012,
                    BrandId = brand.Id,
                    FueldId = fuel.Id,
                    IsAuto = true
                };

                // When
                IList<SearchAdCache> result = adRepo.AdvancedSearchAds<CarAd>(param);

                // Then
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(a, result[0]);
            }
        }