コード例 #1
0
        public void TestViewLoaded()
        {
            Part[] data = new List <Part>()
            {
                new Part()
                {
                    Id = 1
                },
                new Part()
                {
                    Id = 2
                }
            }.ToArray();

            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().GetAllParts()).Returns(data);

            PartsViewModel viewModel = new PartsViewModel(mockServiceFactory.Object);

            Assert.IsTrue(viewModel.Parts == null);

            object loaded = viewModel.ViewLoaded; // fires off the OnViewLoaded protected method

            Assert.IsTrue(viewModel.Parts != null && viewModel.Parts.Count == data.Length && viewModel.Parts[0] == data[0]);
        }
コード例 #2
0
        public void TestEditPartCommand()
        {
            Part part = new Part()
            {
                Id = 1, Description = "Test Description 1"
            };

            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().GetPart(1)).Returns(part);

            PartsViewModel viewModel = new PartsViewModel(mockServiceFactory.Object);

            viewModel.Parts = new ObservableCollection <Part>()
            {
                part
            };

            Assert.IsTrue(viewModel.Parts[0].Description == "Test Description 1");
            Assert.IsTrue(viewModel.CurrentPartViewModel == null);

            viewModel.EditPartCommand.Execute(part);

            Assert.IsTrue(viewModel.CurrentPartViewModel != null);

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().UpdatePart(It.IsAny <Part>())).Returns(viewModel.CurrentPartViewModel.Part);

            viewModel.CurrentPartViewModel.Part.Description = "Note 2";
            viewModel.CurrentPartViewModel.SaveCommand.Execute(null);

            Assert.IsTrue(viewModel.Parts[0].Description == "Note 2");
        }
コード例 #3
0
        private void Load()
        {
            var parts = new PartsViewModel();

            // PartsGrid.ItemsSource = _db.Parts.ToList();
            //dataGrid = PartsGrid;
        }
コード例 #4
0
        public void TestDeletePartCommand()
        {
            Part part = new Part()
            {
                Id = 1, Description = "Test Description 1"
            };

            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().DeletePart(part.Id));

            PartsViewModel viewModel = new PartsViewModel(mockServiceFactory.Object);

            viewModel.Parts = new ObservableCollection <Part>()
            {
                part
            };

            viewModel.ConfirmDelete += (s, e) => e.Cancel = false;

            Assert.IsTrue(viewModel.Parts.Count == 1);

            viewModel.DeletePartCommand.Execute(part);

            Assert.IsTrue(viewModel.Parts.Count == 0);
        }
コード例 #5
0
        public CarPartsAllViewModel GetAllCarsById(int id)
        {
            CarPartsAllViewModel cpvm = new CarPartsAllViewModel();
            var item = this.Context.Cars.Where(s => s.Id == id).First();



            CarPartsViewModel model = new CarPartsViewModel()
            {
                Id              = item.Id,
                Make            = item.Make,
                Model           = item.Model,
                TravellDistance = item.TravelledDistance,
                //SHould set Parts
            };

            foreach (var i in item.Parts)
            {
                PartsViewModel view = new PartsViewModel()
                {
                    Name  = i.Name,
                    Price = i.Price
                };
                model.Parts.Add(view);
            }


            cpvm.CarParts = model;
            return(cpvm);
        }
コード例 #6
0
 private SparePartsDataModel ConvertViewModel_To_DataModel(PartsViewModel p)
 {
     return(new SparePartsDataModel()
     {
         Id = p.Id, Name = p.Name, Price = p.Price
     });
 }
コード例 #7
0
 public void LoadJobNumberCollection()
 {
     parts = new PartsViewModel();
     parts.GetJobNumbers();
     JobNumberListBox.ItemsSource  = null;
     JobNumberListBox.ItemsSource  = parts.JobNumberCollection;
     parts.ExportViewBtnVisibility = false;
 }
コード例 #8
0
        public MainWindow()
        {
            InitializeComponent();

            var dataModel = new DataModel("../../../../database.db");

            DataContext = new PartsViewModel(dataModel);
        }
コード例 #9
0
 private void Load()
 {
     parts = new PartsViewModel();
     parts.GetCategoryNames();
     parts.CatergoryNameCollection.Add("Show All");
     SortCategoryComboBox.ItemsSource = parts.CatergoryNameCollection;
     PartsGrid.ItemsSource            = _db.Parts.ToList();
     dataGrid = PartsGrid;
 }
コード例 #10
0
        // GET: Database
        public ActionResult Parts()
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                PartsViewModel pvm = new PartsViewModel();
                pvm.PartList = db.PARTS.Include("MACHINE").Include("SUPPLIER").Include("OEM").Include("UZAUTOSUPPLIER").Include("MANUFACTURER").Where(p => p.IsDeleted == false).ToList();

                return(View(pvm));
            }
        }
コード例 #11
0
        // GET: Parts
        public async Task <ActionResult> Index()
        {
            PartsViewModel partsVM = new PartsViewModel
            {
                Parts          = await db.Parts.ToListAsync(),
                AvailableParts = await db.AvailableParts.ToListAsync(),
            };

            return(View(partsVM));
        }
コード例 #12
0
        public JsonResult Auth(UserViewModel user)
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                USER account = db.USERS.SingleOrDefault(u => u.Username == user.Username && u.Password == user.Password);

                PartsViewModel pvm = new PartsViewModel();

                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #13
0
        protected override void OnWireViewModelEvents(ViewModelBase viewModel)
        {
            PartsViewModel vm = viewModel as PartsViewModel;

            if (vm != null)
            {
                vm.ConfirmDelete      += OnConfirmDelete;
                vm.ErrorOccured       += OnErrorOccured;
                vm.OpenEditPartWindow += OnOpenEditPartWindow;
            }
        }
コード例 #14
0
        public ActionResult Auth(UserViewModel model)
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                USER user = db.USERS.SingleOrDefault(u => u.Username == model.Username && u.IsDeleted == false);

                PartsViewModel pvm = new PartsViewModel();

                return(RedirectToAction("Index"));
            }
        }
コード例 #15
0
        public async Task <IActionResult> Index(string reference, int productId)
        {
            var vm = new PartsViewModel
            {
                Parts     = await warehouseService.GetParts(),
                Reference = reference,
                ProductId = productId
            };

            return(View(vm));
        }
コード例 #16
0
        private void addBtn_Click(object sender, RoutedEventArgs e)
        {
            PartsViewModel parts = new PartsViewModel();
            int            i     = 9;

            try
            {
                if ((string)catergoeryComboBox.SelectedItem != "")
                {
                    var categoery = _db.Catergoeries.ToList();
                    i = categoery.First(c => c.Name == (string)catergoeryComboBox.SelectedItem).Id;
                }
            }
            catch (Exception ex)
            {
                //throw;
            }
            if (descTextBox.Text == "")
            {
                MessageBox.Show("Please enter a description to this part before adding");
            }
            else if (partNumTextBox.Text == "")
            {
                MessageBox.Show("Please enter a part number to this part before adding");
            }
            else
            {
                bool exists = parts.CheckIfPartNumberCreated(partNumTextBox.Text);
                if (!exists)
                {
                    Part newPart = new Part()
                    {
                        Description  = descTextBox.Text,
                        PartNumber   = partNumTextBox.Text,
                        Link         = linkTextBox.Text,
                        Supplier     = supplierTextBox.Text,
                        Price        = priceTextBox.Text,
                        CatergoeryId = i
                    };

                    _db.Parts.Add(newPart);
                    _db.SaveChanges();
                    MainWindow.frame.Content = new PartsHomePage();
                    MessageBox.Show($"Part Number {newPart.PartNumber} was added to the database");
                }

                else
                {
                    MessageBox.Show("There is already a part created with this part number.\nCheck parts list to update this part\nor change part number");
                }
                //Load();
            }
        }
        public ActionResult DropDown()
        {
            PartsViewModel partsViewModel = new PartsViewModel();

            //Get list of options
            utility utility     = new utility();
            var     sortOptions = utility.GetOptions();

            //DropDownList property of view model will contain a list of all options.
            partsViewModel.DropDownList = utility.SetOptions(sortOptions);

            return(View(partsViewModel));
        }
コード例 #18
0
        public ActionResult PartsInsertOrEdit(int partID)
        {
            using (DBEPREntities db = new DBEPREntities())
            {
                PartsViewModel pvm = new PartsViewModel();
                //for Modals:
                List <SUPPLIER> sList = db.SUPPLIERS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.SupplierList = new SelectList(sList, "ID", "Name");
                List <MACHINE> mList = db.MACHINES.Where(s => s.IsDeleted == false).ToList();
                ViewBag.MachineList = new SelectList(mList, "ID", "Name");
                List <MANUFACTURER> manList = db.MANUFACTURERS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.ManufacturerList = new SelectList(manList, "ID", "Name");
                List <OEM> oList = db.OEMS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.OEMList = new SelectList(oList, "ID", "Name");
                List <UZAUTOSUPPLIER> uList = db.UZAUTOSUPPLIERS.Where(s => s.IsDeleted == false).ToList();
                ViewBag.UzAutoSupplierList = new SelectList(uList, "ID", "Name");

                if (partID > 0)
                {
                    PART part = db.PARTS.SingleOrDefault(p => p.IsDeleted == false && p.ID == partID);
                    if (part != null)
                    {
                        pvm.ID                = part.ID;
                        pvm.Name              = part.Name;
                        pvm.NameRus           = part.NameRus;
                        pvm.Description       = part.Description;
                        pvm.DescriptionRus    = part.DescriptionRus;
                        pvm.Code              = part.Code;
                        pvm.Currency          = part.Currency;
                        pvm.Manufactured_Date = part.Manufactured_Date;
                        pvm.PartNumber        = part.PartNumber;
                        pvm.Modeli            = part.Modeli;
                        pvm.OEMPartNumber     = part.OEMPartNumber;
                        pvm.Price             = part.Price;
                        pvm.SerialNumber      = part.SerialNumber;
                        pvm.TechData          = part.TechData;
                        pvm.Type              = part.Type;
                        pvm.Unit              = part.Unit;
                        pvm.MachineID         = part.MachineID;
                        pvm.ManufacturerID    = part.ManufacturerID;
                        pvm.SupplierID        = part.SupplierID;
                        pvm.OEMID             = part.OEMID;
                        pvm.UzAutoSupplierID  = part.UzAutoSupplierID;
                    }
                }
                return(PartialView("PartsInsertOrEdit", pvm));
            }
        }
コード例 #19
0
        public PartsListControl(IPartRepository partRepository)
        {
            _partRepository = partRepository;
            _acad           = new AutoCadManager();

            ViewModel = new PartsViewModel(_partRepository);
            ViewModel.Reset.Subscribe(ResetImpl);

            ViewModel.DeleteSelectedPart.Subscribe(DeleteSelectedPartImpl);
            ViewModel.EditSelectedPart.Subscribe(p => OpenPartWindow(p as Part));
            ViewModel.CreatePart.Subscribe(_ => OpenPartWindow(new Part()));
            ViewModel.Analyze.Subscribe(_ => AnalyzeImpl());

            DataContext = ViewModel;
            InitializeComponent();
        }
        public ActionResult DropDown(PartsViewModel partsViewModel)
        {
            if (ModelState.IsValid)
            {
                {
                    //'PartsViewModel.DropDownValue' property will contain your selected value
                    //Do your stuff with this value such as DB update, etc
                }

                //Get list of options
                utility utility     = new utility();
                var     sortOptions = utility.GetOptions();

                //DropDownList property of view model will contain a list of all options.
                partsViewModel.DropDownList = utility.SetOptions(sortOptions);
            }
            return(View(partsViewModel));
        }
コード例 #21
0
        public void TestCurrentPartSetting()
        {
            Part part = new Part()
            {
                Id = 1
            };

            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().GetPart(1)).Returns(part);

            PartsViewModel viewModel = new PartsViewModel(mockServiceFactory.Object);

            Assert.IsTrue(viewModel.CurrentPartViewModel == null);

            viewModel.EditPartCommand.Execute(part);

            Assert.IsTrue(viewModel.CurrentPartViewModel != null && viewModel.CurrentPartViewModel.Part.Id == part.Id);
        }
コード例 #22
0
        public IActionResult Index()
        {
            var viewModel = new PartsViewModel
            {
                CpuCoolings      = _context.CpuCoolings.ToList(),
                Cases            = _context.Cases.ToList(),
                GraphicsCards    = _context.GraphicsCards.ToList(),
                Processors       = _context.Processors.ToList(),
                CdDvds           = _context.CdDvds.ToList(),
                Coolings         = _context.Coolings.ToList(),
                HardDrives       = _context.HardDrives.ToList(),
                Motherboards     = _context.Motherboards.ToList(),
                OperatingSystems = _context.OperatingSystems.ToList(),
                PowerSupplies    = _context.PowerSupplies.ToList(),
                Rams             = _context.Rams.ToList(),
                SoundCards       = _context.SoundCards.ToList()
            };

            return(View(viewModel));
        }
コード例 #23
0
        public void TestAddPartCommand()
        {
            Mock <IServiceFactory> mockServiceFactory = new Mock <IServiceFactory>();

            PartsViewModel viewModel = new PartsViewModel(mockServiceFactory.Object);

            viewModel.Parts = new ObservableCollection <Part>();

            Assert.IsTrue(viewModel.CurrentPartViewModel == null);

            viewModel.AddPartCommand.Execute(null);

            Assert.IsTrue(viewModel.CurrentPartViewModel != null);
            viewModel.CurrentPartViewModel.Part.Description = "Test Part";

            mockServiceFactory.Setup(mock => mock.CreateClient <IPartService>().UpdatePart(It.IsAny <Part>())).Returns(viewModel.CurrentPartViewModel.Part);

            viewModel.CurrentPartViewModel.SaveCommand.Execute(null);

            Assert.IsNotNull(viewModel.Parts);
            Assert.AreEqual(1, viewModel.Parts.Count);
        }
コード例 #24
0
 public void Update(AiCiBaE2C_Model model)
 {
     Clear();
     ph_am      = model.symbols[0].ph_am;
     ph_am_mp3  = model.symbols[0].ph_am_mp3;
     ph_en      = model.symbols[0].ph_am;
     ph_en_mp3  = model.symbols[0].ph_en_mp3;
     word_pl    = SerilizeStringFromArray(model.exchange.word_pl);
     word_past  = SerilizeStringFromArray(model.exchange.word_past);
     word_done  = SerilizeStringFromArray(model.exchange.word_done);
     word_ing   = SerilizeStringFromArray(model.exchange.word_ing);
     word_third = SerilizeStringFromArray(model.exchange.word_third);
     word_er    = SerilizeStringFromArray(model.exchange.word_er);
     word_est   = SerilizeStringFromArray(model.exchange.word_est);
     foreach (var item in ObservableCollectionHelper.GetObservableCollectionFromArray(model.symbols[0].parts))
     {
         PartsViewModel.Add(new PartsViewModel_AiCiBa()
         {
             part = item.part,
             mean = SerilizeStringFromArray(item.means)
         });
     }
 }
コード例 #25
0
 public void Clear()
 {
     PartsViewModel.Clear();
 }
コード例 #26
0
        public ActionResult PartsSave(PartsViewModel model)
        {
            ///////////////////////////////////////////
            string        connetionString;
            SqlConnection cnn;

            connetionString = @"Data Source=89.236.217.150;Initial Catalog=DBEPR;User ID=EPRuser;Password=Zxcv!123";
            cnn             = new SqlConnection(connetionString);
            cnn.Open();
            string sql = @"INSERT INTO testtable (id,test) VALUES ('xxxx','ZZZ')";

            using (SqlCommand cmd = new SqlCommand(sql, cnn))
            {
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
            }
            cnn.Close();
            ////////////////////////////////////////////
            ///
            using (DBEPREntities db = new DBEPREntities())
            {
                if (model.ID > 0)
                {
                    PART part = db.PARTS.SingleOrDefault(p => p.IsDeleted == false && p.ID == model.ID);
                    if (part != null)
                    {
                        part.ID                = model.ID;
                        part.Name              = model.Name;
                        part.NameRus           = model.NameRus;
                        part.Description       = model.Description;
                        part.DescriptionRus    = model.DescriptionRus;
                        part.Code              = model.DescriptionRus;
                        part.Currency          = model.Currency;
                        part.Manufactured_Date = model.Manufactured_Date;
                        part.Modeli            = model.Modeli;
                        part.OEMPartNumber     = model.OEMPartNumber;
                        part.Price             = model.Price;
                        part.SerialNumber      = model.SerialNumber;
                        part.TechData          = model.TechData;
                        part.Type              = model.Type;
                        part.Unit              = model.Unit;
                        part.MachineID         = model.MachineID;
                        part.ManufacturerID    = model.ManufacturerID;
                        part.SupplierID        = model.SupplierID;
                        part.OEMID             = model.OEMID;
                        part.UzAutoSupplierID  = model.UzAutoSupplierID;

                        db.SaveChanges();
                    }
                }
                else
                {
                    PART p = new PART();

                    p.Code             = model.Code;
                    p.Description      = model.Description;
                    p.DescriptionRus   = model.DescriptionRus;
                    p.MachineID        = model.MachineID;
                    p.SupplierID       = model.SupplierID;
                    p.OEMID            = model.OEMID;
                    p.ManufacturerID   = model.ManufacturerID;
                    p.UzAutoSupplierID = model.UzAutoSupplierID;
                    p.PartNumber       = model.PartNumber;
                    p.OEMPartNumber    = model.OEMPartNumber;
                    //p.NamePlate = model.NamePlate;
                    p.Name              = model.Name;
                    p.NameRus           = model.NameRus;
                    p.Modeli            = model.Modeli;
                    p.Type              = model.Type;
                    p.SerialNumber      = model.SerialNumber;
                    p.Manufactured_Date = model.Manufactured_Date;
                    p.TechData          = model.TechData;
                    p.Unit              = model.Unit;
                    p.Price             = model.Price;
                    p.Currency          = model.Currency;
                    p.IsDeleted         = false;

                    db.PARTS.Add(p);
                    db.SaveChanges();
                }

                return(View(model));
            }
        }