public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(View(category));
            }
            _context.Add(category);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,ImageMimeType,Thumbnail,ImageData")] Image image)
        {
            if (!ModelState.IsValid)
            {
                return(View(image));
            }

            _context.Add(image);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(ComponentViewModel componentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(componentViewModel));
            }

            var type = _context.Types.FirstOrDefault(x => x.Id == int.Parse(componentViewModel.TypeId));

            componentViewModel.Component.Type   = type;
            componentViewModel.Component.TypeId = (int)type.Id;

            _context.Add(componentViewModel.Component);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#4
0
        public async Task <IActionResult> Create(TypeViewModel typeViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(typeViewModel));
            }

            var categories = _context.Categories
                             .Where(l => typeViewModel.SelectedCategories.Contains(l.Id.ToString()));

            typeViewModel.Type.CategoryTypes = new List <CategoryType>();
            foreach (var category in categories)
            {
                typeViewModel.Type.CategoryTypes.Add(new CategoryType {
                    CategoryId = category.Id, Type = typeViewModel.Type
                });
            }

            _context.Add(typeViewModel.Type);
            await _context.SaveChangesAsync();

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