public async Task <IActionResult> Create(CreateComponentTypeViewModel componentTypeViewModel)
        {
            if (ModelState.IsValid)
            {
                //Make image
                byte[] image;
                byte[] thumbnail;
                using (var m = new MemoryStream())
                {
                    await componentTypeViewModel.ImageUpload.CopyToAsync(m);

                    image = m.ToArray();
                }
                //Make thumbnail
                using (var m = new MemoryStream())
                {
                    await componentTypeViewModel.ImageUpload.CopyToAsync(m);

                    using (var ti = new FreeImageBitmap(componentTypeViewModel.ImageUpload.OpenReadStream()))
                    {
                        var thumb = ti.GetThumbnailImage(100, true);
                        using (var nm = new MemoryStream())
                        {
                            thumb.Save(nm, Util.Util.FindImageFormat(componentTypeViewModel.ImageUpload.ContentType));
                            thumbnail = nm.ToArray();
                        }
                    }
                }
                var componentType = new ComponentType
                {
                    ComponentName = componentTypeViewModel.ComponentName,
                    AdminComment  = componentTypeViewModel.AdminComment,
                    ComponentInfo = componentTypeViewModel.ComponentInfo,
                    Datasheet     = componentTypeViewModel.Datasheet,
                    Location      = componentTypeViewModel.Location,
                    WikiLink      = componentTypeViewModel.WikiLink,
                    Manufacturer  = componentTypeViewModel.Manufacturer,
                    Image         = new EsImage
                    {
                        ImageData     = image,
                        Thumbnail     = thumbnail,
                        ImageMimeType = componentTypeViewModel.ImageUpload.ContentType
                    }
                };
                var category = await _context.Categories.FirstOrDefaultAsync(c => c.CategoryId == componentTypeViewModel.Category);

                if (category != null)
                {
                    _context.Add(componentType);
                    await _context.SaveChangesAsync();

                    _context.Add(new ComponentTypeCategory {
                        Category = category, ComponentType = componentType
                    });
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentTypeViewModel));
        }
        public async Task <IActionResult> Create([Bind("CategoryId,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("ComponentId,ComponentTypeId,ComponentNumber,SerialNo,Status,AdminComment,UserComment,CurrentLoanInformationId")] Component component)
        {
            if (ModelState.IsValid)
            {
                _context.Add(component);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(component));
        }