public async Task <IActionResult> Create([Bind("ComponentTypeId,ComponentName,ComponentInfo,Location,Status,Datasheet,ImageUrl,Manufacturer,WikiLink,AdminComment")] ComponentType componentType, IFormCollection formCollection) { if (ModelState.IsValid) { var selectedValues = formCollection["categories"].ToString(); var splitSelected = selectedValues.Split(","); var allCategories = _categoryRepository.GetAll().ToList(); foreach (var typeId in splitSelected) { foreach (var cat in allCategories) { if (cat.CategoryId.ToString() == typeId) { _context.CategoryComponentTypes.Add(new CategoryComponentType { Category = cat, ComponentType = componentType }); } } } _context.Add(componentType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(componentType)); }
public async Task <IActionResult> Create([Bind("Name, SelectedComponentTypes")] CategoryViewModel categoryVM) { if (ModelState.IsValid) { Category tempCategory = new Category() { Name = categoryVM.Name, }; Category category = _context.Add(tempCategory).Entity; foreach (var id in categoryVM.SelectedComponentTypes) { ComponentType componentType = _context.ComponentType.Find(long.Parse(id)); ComponentTypeCategory tempCtc = new ComponentTypeCategory { Category = category, ComponentType = componentType }; ComponentTypeCategory ctc = _context.Add(tempCtc).Entity; } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categoryVM)); }
public async Task <IActionResult> Create([Bind("CategoryId,Name")] Category category, IFormCollection formCollection) { if (ModelState.IsValid) { var selectedValues = formCollection["types"].ToString(); var splitSelected = selectedValues.Split(","); var allTypes = _componentTypeRepository.GetAll().ToList(); foreach (var typeId in splitSelected) { foreach (var type in allTypes) { if (type.ComponentTypeId.ToString() == typeId) { _context.CategoryComponentTypes.Add(new CategoryComponentType { Category = category, ComponentType = type }); } } } _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ESImageId,ImageMimeType,Thumbnail,ImageData")] ESImage eSImage) { if (ModelState.IsValid) { _context.Add(eSImage); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(eSImage)); }
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)); }
public async Task <IActionResult> Create([Bind("SelectedCategories, ComponentName,ComponentInfo,Location,Status,Datasheet,ImageUrl,Manufacturer,WikiLink,AdminComment")] ComponentTypeViewModel vm) { if (ModelState.IsValid) { ComponentType tempComponentType = new ComponentType() { ComponentName = vm.ComponentName, AdminComment = vm.AdminComment, ComponentInfo = vm.ComponentInfo, Datasheet = vm.Datasheet, Location = vm.Location, WikiLink = vm.WikiLink, Status = vm.Status, Manufacturer = vm.Manufacturer, ImageUrl = vm.ImageUrl, Image = vm.Image, }; try { var componentType = _context.Add(tempComponentType).Entity; foreach (var id in vm.SelectedCategories) { Category cat = _context.Category.Find(long.Parse(id)); if (cat != null) { ComponentTypeCategory ctc = new ComponentTypeCategory { Category = cat, ComponentType = componentType, }; _context.Add(ctc); } } await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } return(RedirectToAction(nameof(Index))); } return(View(vm)); }
public async Task <IActionResult> Create([Bind("Id,Name,UserRole, Password")] User user) { if (ModelState.IsValid) { var u1 = new User { Name = user.Name, Password = BCrypt.Net.BCrypt.HashPassword(user.Password), UserRole = user.UserRole }; _context.Add(u1); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }