示例#1
0
        public IActionResult EditComponentType(string button, ComponentType input, IFormFile image, List <long> categoryIds)
        {
            switch (button)
            {
            case "Cancel":
                return(RedirectToAction("Index"));

            case "Update":
                if (image == null)
                {
                    var oldComponent = _componentTypeRepository.GetComponentType(input.ComponentTypeId);
                    input.Image = oldComponent.Image;
                }
                if (image != null)
                {
                    using (var ms = image.OpenReadStream())
                    {
                        var buffer = new byte[ms.Length];
                        ms.Seek(0, SeekOrigin.Begin);
                        ms.ReadAsync(buffer, 0, (int)ms.Length);
                        var esImage = new ESImage {
                            ImageData = buffer
                        };
                        input.Image = esImage;
                    }
                }

                _componentTypeRepository.UpdateComponentType(input);
                var categories = _categoryRepository.GetAllCategories()
                                 .Where(category => categoryIds.Contains(category.CategoryId))
                                 .ToList();

                _componentTypeCategoryRepository.ClearComponentTypeCategoriesForComponentType(input.ComponentTypeId);

                foreach (var category in categories)
                {
                    _componentTypeCategoryRepository.CreateComponentTypeCategory(input, category);
                }
                return(RedirectToAction("Index"));

            default:
                return(RedirectToAction("Index"));
            }
        }
        public async Task <ActionResult <ComponentType> > GetEntityType(int?id)
        {
            if (id == null)
            {
                return(NotFound("Bad parameter"));
            }

            var componentType = await _repository.GetComponentType(id);

            if (componentType == null)
            {
                return(NotFound());
            }
            return(componentType);
        }
        public IActionResult ManageComponent(long componentId, string buttonValue)
        {
            ViewBag.ComponentTypes = new SelectList(_componentTypeRepository.GetAllComponentTypes(), "ComponentTypeId", "ComponentName");
            var component = _componentRepository.GetComponent(componentId);

            switch (buttonValue)
            {
            case "Details":
                ComponentType componentType = _componentTypeRepository.GetComponentType(component.ComponentTypeId);
                ViewBag.ComponentTypeName = componentType.ComponentName;

                return(View("ComponentDetails", component));

            case "Edit":
                return(View("EditComponent", component));

            case "Delete":
                _componentRepository.DeleteComponent(componentId);
                return(Index());

            default:
                return(Index());
            }
        }
示例#4
0
 public ComponentType CreatComponents(Guid id)
 {
     return(componentTypeRepository.GetComponentType(id));
 }