public IActionResult Edit(int id)
        {
            //needs to find a component with its componenttype
            var compVM = new ComponentViewModel();
            var comp   = new Component();

            using (var db = new EmbeddedStockContext())
            {
                comp = db.Components.Find(id);
            }

            compVM.ComponentId     = comp.ComponentId;
            compVM.ComponentNumber = comp.ComponentNumber;
            compVM.ComponentTypeId = comp.ComponentTypeId;
            compVM.SearchTerm      = comp.SearchTerm;
            compVM.SerialNo        = comp.SerialNo;


            //var com = new ComponentType();
            //com.ComponentName = "hej";
            //com.ComponentTypeId = 1;
            //var com2 = new ComponentType();
            //com2.ComponentName = "hedsadasj";
            //com2.ComponentTypeId = 2;
            //cat.ComponentType = com;
            ViewBag.list = _typeRepo.GetAll().ToList <ComponentType>();
            return(View(compVM));
        }
示例#2
0
        public IActionResult Create(CategoryViewModel model)
        {
            //needs to create a category and create the binding to the chosen componenttypes


            using (var db = new EmbeddedStockContext())
            {
                var cat = new Category();
                cat.Name = model.Name;
                db.Categories.Add(cat);


                if (model.ComponentTypeIds != null)
                {
                    foreach (int id in model.ComponentTypeIds)
                    {
                        var type   = db.ComponentTypes.Find(id);
                        var cattyp = new CategoryComponentType()
                        {
                            Category = cat, ComponentType = type
                        };
                        db.CategoryComponentTypes.Add(cattyp);
                    }
                }


                db.SaveChanges();
            }


            return(RedirectToAction("", "category", new { area = "" }));
        }
 public ComponentTypeFormController(IComponentRepository componentRepository, ICategoryRepository categoryRepository, IComponentTypeRepository componentTypeRepository, EmbeddedStockContext context)
 {
     _componentTypeRepository = componentTypeRepository;
     _categoryRepository      = categoryRepository;
     _context             = context;
     _componentRepository = componentRepository;
 }
示例#4
0
        public IActionResult Show(int id)
        {
            //needs to find a category with its componenttype names in the list

            //cat.Name = "hejhejhej";
            //ComponentType com = new ComponentType();
            //com.ComponentName = "efdsdf";
            //com.ComponentTypeId = 1;

            List <ComponentType> tempList = new List <ComponentType>();
            Category             cat      = new Category();

            using (var db = new EmbeddedStockContext())
            {
                tempList = db.CategoryComponentTypes.Include(ct => ct.ComponentType)
                           .Where(c => c.CategoryId == id)
                           .Select(c => c.ComponentType)
                           .ToList();

                cat = db.Categories.Find(id);
            }



            ViewBag.componentList = tempList;
            ViewBag.category      = cat;
            return(View());
        }
示例#5
0
        public IActionResult Update(CategoryViewModel model)
        {
            using (var db = new EmbeddedStockContext())
            {
                var edit = new Category {
                    CategoryId = model.Id, Name = model.Name
                };
                db.Categories.Attach(edit);
                var entry = db.Entry(edit);
                entry.Property(e => e.Name).IsModified = true;

                db.CategoryComponentTypes.RemoveRange(db.CategoryComponentTypes.Where(c => c.CategoryId == model.Id));

                foreach (int id in model.ComponentTypeIds)
                {
                    var type = db.ComponentTypes.Find(id);
                    var cat  = db.Categories.Find(model.Id);

                    var cattyp = new CategoryComponentType()
                    {
                        Category = cat, ComponentType = type
                    };
                    db.CategoryComponentTypes.Add(cattyp);
                }

                db.SaveChanges();
            }

            //find category and update with new name and component types
            return(RedirectToAction("", "category", new { area = "" }));
        }
示例#6
0
        public IActionResult Delete(int id)
        {
            using (var db = new EmbeddedStockContext())
            {
                var del = new Category {
                    CategoryId = id
                };
                db.Categories.Remove(del);
                db.SaveChanges();
            }

            return(RedirectToAction("", "category", new { area = "" }));
        }
示例#7
0
        public IActionResult Show(int id)
        {
            Category cat = new Category();

            cat.Name = "hejhejhej";
            //ComponentType comtype = new ComponentType();
            //comtype.ComponentName = "efdsdf";
            //comtype.ComponentTypeId = 1;
            //var com = new Component();
            //com.ComponentId = 1;
            //com.ComponentNumber = 3;
            //needs to find a Componenttype with its categories names and components in 2 lists

            List <Component> tempList    = new List <Component>();
            ComponentType    tempComp    = new ComponentType();
            List <Category>  tempCatlist = new List <Category>();

            using (var db = new EmbeddedStockContext())
            {
                var query = from c in db.Components
                            where c.ComponentTypeId == id
                            select c;

                tempList = query.ToList();

                tempComp = db.ComponentTypes.Find(id);


                tempCatlist = db.CategoryComponentTypes.Include(ct => ct.Category)
                              .Where(c => c.ComponentTypeId == id)
                              .Select(c => c.Category)
                              .ToList();
            }

            ViewBag.componentList = tempList;



            var stringlist = new List <string> ();

            foreach (Category cate in tempCatlist)
            {
                stringlist.Add(cate.Name);
            }

            ViewBag.categoryNames  = stringlist;
            ViewBag.component_type = tempComp;
            return(View());
        }
        public IActionResult Delete(int id)
        {
            //delete category and its bindings to componttypes
            using (var db = new EmbeddedStockContext())
            {
                var del = new Component {
                    ComponentId = id
                };
                db.Components.Remove(del);
                db.SaveChanges();
            }


            return(RedirectToAction("", "component", new { area = "" }));
        }
        public IActionResult Create(ComponentViewModel model)
        {
            //needs to create a category and create the binding to the chosen componenttypes

            using (var db = new EmbeddedStockContext())
            {
                var com = new Component();
                com.ComponentNumber = model.ComponentNumber;
                com.SerialNo        = model.SerialNo;
                com.ComponentTypeId = model.ComponentTypeId;
                db.Components.Add(com);
                db.SaveChanges();
            }

            return(RedirectToAction("", "component", new { area = "" }));
        }
        public IActionResult Show(int id)
        {
            //needs to find a component with its componenttype names in the list
            var comp = new Component();


            var com = new ComponentType();


            using (var db = new EmbeddedStockContext())
            {
                comp = db.Components.Find(id);
                com  = db.ComponentTypes.Find(comp.ComponentTypeId);
            }

            ViewBag.component = comp;

            ViewBag.componentType = com;
            return(View());
        }
        public IActionResult Index()
        {
            var cat = new ComponentViewModel();

            cat.ComponentNumber = 1231345454;
            //needs list of all component
            cat.SerialNo    = "12a3ds12a";
            cat.ComponentId = 2;
            var com = new ComponentType();

            com.ComponentName   = "hej";
            com.ComponentTypeId = 1;

            using (var db = new EmbeddedStockContext())
            {
                ViewBag.list = db.Components.ToList <Component>();
            }

            return(View());
        }
        public IActionResult Search(ComponentViewModel model)
        {
            var cat = new ComponentViewModel();

            cat.ComponentNumber = 1231345454;
            //needs list of all component
            cat.SerialNo    = "12a3ds12a";
            cat.ComponentId = 2;
            var com = new ComponentType();

            com.ComponentName   = "hej";
            com.ComponentTypeId = 1;
            //cat.ComponentType = com;
            //show filtered list of Components in shape of a viewmodel


            using (var db = new EmbeddedStockContext())
            {
                // ViewBag.list = db.Components.ToList<Component>();

                if (model.SearchTerm != null)
                {
                    var tempS = db.Components.Where(c => c.ComponentNumber.ToString().Contains(model.SearchTerm));

                    ViewBag.list = tempS.ToList <Component>();
                }

                else
                {
                    ViewBag.list = db.Components.ToList <Component>();
                }
            }



            return(View("Index", model));
        }
示例#13
0
        public static void Initializer(EmbeddedStockContext context)
        {
            context.Database.EnsureCreated();


            if (context.Components.Any())
            {
                return;
            }

            var component1 = new Component {
                ComponentNumber = 89,
                SerialNo        = "KL89",
                Status          = ComponentStatus.Available,
                AdminComment    = "Working",
                UserComment     = "A small flaw"
            };
            var component2 = new Component {
                ComponentNumber = 42,
                SerialNo        = "ML42",
                Status          = ComponentStatus.Loaned,
                AdminComment    = "User au593874 has it",
                UserComment     = "I'm keeping it"
            };
            var image = new Byte[0];//System.IO.File.ReadAllBytes("resistor.jpg");

            var esimage = new ESImage {
                ImageData     = image,
                Thumbnail     = image,
                ImageMimeType = "image/jpeg"
            };
            var componenttype = new ComponentType
            {
                ComponentName = "Resistor",
                ComponentInfo = "Just a resistor",
                Location      = "in yer butt",
                Status        = ComponentTypeStatus.Available,
                Datasheet     = "data",
                ImageUrl      = "url",
                Image         = esimage,
                Manufacturer  = "Poul Ejnar A/S",
                WikiLink      = "wikilink",
                AdminComment  = "comment"
            };

            componenttype.Components.Add(component1);
            componenttype.Components.Add(component2);
            var category = new Category
            {
                Name = "Test"
            };

            var categoryComponentType = new CategoryComponentType
            {
                Category      = category,
                ComponentType = componenttype
            };

            context.CategoryComponentTypes.Add(categoryComponentType);
            context.SaveChanges();
        }
 public ESImageController(EmbeddedStockContext context)
 {
     _context = context;
 }
示例#15
0
 public ComponentFormController(EmbeddedStockContext context, IComponentTypeRepository typeDb)
 {
     _context = context;
     _typeDb  = typeDb;
 }
示例#16
0
 public CategoryRepository(EmbeddedStockContext context) => _context = context;
 public ComponentTypeController(EmbeddedStockContext context)
 {
     _context = context;
 }
 public ComponentRepository(EmbeddedStockContext context) => _context = context;
 public GeneriskRepository(EmbeddedStockContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
 public UsersController(EmbeddedStockContext context)
 {
     _context = context;
 }
示例#21
0
 public CategoryController(EmbeddedStockContext context)
 {
     _context = context;
 }
 public LoginController(EmbeddedStockContext embeddedStock, IValidationService validationService)
 {
     _embeddedStock     = embeddedStock;
     _validationService = validationService;
 }