public async Task <IActionResult> Edit(long id, [Bind("ESImageId,ImageMimeType,Thumbnail,ImageData")] ESImage eSImage)
        {
            if (id != eSImage.ESImageId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eSImage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ESImageExists(eSImage.ESImageId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(eSImage));
        }
예제 #2
0
        public async Task <IActionResult> Edit(long id, [Bind("ComponentId,ComponentTypeId,ComponentNumber,SerialNo,Status,AdminComment,UserComment,CurrentLoanInformationId")] Component component)
        {
            if (id != component.ComponentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(component);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponentExists(component.ComponentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.types = _typeDb.GetAll();
            return(View(component));
        }
        public async Task <IActionResult> Edit(long id, [Bind("ComponentTypeId,ComponentName,ComponentInfo,Location,Status,Datasheet,ImageUrl,Manufacturer,WikiLink,AdminComment")] ComponentType componentType)
        {
            if (id != componentType.ComponentTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(componentType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponentTypeExists(componentType.ComponentTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentType));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,UserRole")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
예제 #5
0
        public async Task <IActionResult> Edit(long id, [Bind("Name, SelectedComponentTypes, CategoryId")] CategoryViewModel vm)
        {
            if (id != long.Parse(vm.CategoryId))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                // Find category including the linked ComponentTypeCategories
                Category category = _context.Category
                                    .Include(c => c.ComponentTypeCategories)
                                    .Single(c => c.CategoryId == id);

                category.Name = vm.Name;

                foreach (var sid in vm.SelectedComponentTypes)
                {
                    ComponentType componentType = _context.ComponentType.Find(long.Parse(sid));

                    var isPresent = category.ComponentTypeCategories.Single(ctc => ctc.ComponentType == componentType);

                    if (isPresent == null)
                    {
                        var tempCtc = new ComponentTypeCategory
                        {
                            Category      = category,
                            ComponentType = componentType
                        };
                        ComponentTypeCategory ctc = _context.Add(tempCtc).Entity;

                        category.ComponentTypeCategories.Add(ctc);
                    }
                }

                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vm));
        }
        public async Task <IActionResult> Edit(long id, [Bind("ComponentTypeId,ComponentName,ComponentInfo,Location,Status,Datasheet,ImageUrl,Manufacturer,WikiLink,AdminComment")] ComponentType componentType, IFormCollection formCollection)
        {
            if (id != componentType.ComponentTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var      selectedValues = formCollection["categories"].ToString();
                    string[] splitSelected  = new string[0];
                    if (!string.IsNullOrEmpty(selectedValues))
                    {
                        splitSelected = selectedValues.Split(",");
                    }

                    var categoriesOfType = await _context.CategoryComponentTypes
                                           .Where(cc => cc.ComponentTypeId == id)
                                           .Select(cc => cc.Category)
                                           .ToListAsync();

                    foreach (var categoryId in splitSelected)
                    {
                        var category = _categoryRepository.GetById(Int32.Parse(categoryId));



                        if (!categoriesOfType.Contains(category))
                        {
                            _context.CategoryComponentTypes.Add(new CategoryComponentType {
                                Category = category, ComponentType = componentType
                            });
                        }
                    }

                    foreach (var type in categoriesOfType)
                    {
                        if (!splitSelected.Contains(type.CategoryId.ToString()))
                        {
                            var catCompType = await _context.CategoryComponentTypes
                                              .Where(cc => cc.CategoryId == type.CategoryId &&
                                                     cc.ComponentTypeId == id).SingleOrDefaultAsync();

                            if (catCompType != null)
                            {
                                _context.CategoryComponentTypes.Remove(catCompType);
                                _context.SaveChanges();
                            }
                        }
                    }
                    _context.Update(componentType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ComponentTypeExists(componentType.ComponentTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(componentType));
        }
예제 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,Name")] Category category, IFormCollection formCollection)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var      selectedValues = formCollection["types"].ToString();
                    string[] splitSelected  = new string[0];
                    if (!string.IsNullOrEmpty(selectedValues))
                    {
                        splitSelected = selectedValues.Split(",");
                    }

                    var allTypes = _componentTypeRepository.GetAll().ToList();

                    var typesOfCategory = await _context.CategoryComponentTypes
                                          .Where(cc => cc.CategoryId == id)
                                          .Select(cc => cc.ComponentType)
                                          .ToListAsync();

                    foreach (var typeId in splitSelected)
                    {
                        var componentType = _componentTypeRepository.GetById(Int32.Parse(typeId));



                        if (!typesOfCategory.Contains(componentType))
                        {
                            _context.CategoryComponentTypes.Add(new CategoryComponentType {
                                Category = category, ComponentType = componentType
                            });
                        }
                    }

                    foreach (var type in typesOfCategory)
                    {
                        if (!splitSelected.Contains(type.ComponentTypeId.ToString()))
                        {
                            var catCompType = await _context.CategoryComponentTypes
                                              .Where(cc => cc.ComponentTypeId == type.ComponentTypeId &&
                                                     cc.CategoryId == id).SingleOrDefaultAsync();

                            if (catCompType != null)
                            {
                                _context.CategoryComponentTypes.Remove(catCompType);
                                _context.SaveChanges();
                            }
                        }
                    }

                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }