Example #1
0
        public async Task <IActionResult> ModifyCube(long identity)
        {
            var cube = await _cubeSrvice.GetCubeAsync(identity);

            if (cube != null)
            {
                var model = new CrudCubeModel
                {
                    PlasticColors = await _cubeSrvice.GetAllPlasticColorsAsync(),
                    Manufacturers = await _cubeSrvice.GetAllManufacturersAsync(),
                    Categories    = await _categoryService.GetAllCategoriesAsync(),

                    CubeID         = cube.Identity,
                    CategoryID     = cube.Category.Identity,
                    ManufacturerID = cube.Manufacturer.Identity,
                    PlasticColorID = cube.PlasticColor.Identity,
                    ModelName      = cube.ModelName,
                    ReleaseYear    = cube.ReleaseYear,
                    WcaPermission  = cube.WcaPermission
                };

                return(View(model));
            }

            return(RedirectToAction("Summary"));
        }
Example #2
0
        public async Task <IActionResult> ModifyCube(CrudCubeModel model)
        {
            if (ModelState.IsValid)
            {
                var manufacturer = await _cubeSrvice.GetManufacturerAsync(model.ManufacturerID);

                var plasticColor = (await _cubeSrvice.GetAllPlasticColorsAsync()).FirstOrDefault(pc => pc.Identity == model.PlasticColorID);
                var category     = await _categoryService.GetCategoryAsync(model.CategoryID);

                if (manufacturer != null && plasticColor != null && category != null)
                {
                    var result = await _cubeSrvice.UpdateCubeAsync(model.CubeID, category, plasticColor,
                                                                   manufacturer, model.ModelName, model.ReleaseYear, model.WcaPermission);

                    if (result.IsFaulted)
                    {
                        foreach (var message in result.Messages)
                        {
                            ModelState.AddModelError(string.Empty, message);
                        }
                    }
                    else
                    {
                        return(RedirectToAction("Summary"));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, ApplicationResources.UserInterface.ModelsValidationMessages.InvalidParameters);
                }
            }

            model.PlasticColors = await _cubeSrvice.GetAllPlasticColorsAsync();

            model.Manufacturers = await _cubeSrvice.GetAllManufacturersAsync();

            model.Categories = await _categoryService.GetAllCategoriesAsync();

            return(View(model));
        }