示例#1
0
        public async Task <IActionResult> Create(LoadFormatViewModel viewModel)
        {
            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));

            if (ModelState.IsValid)
            {
                LoadFormat loadFormat = new LoadFormat();
                loadFormat           = viewModel.LoadFormat;
                loadFormat.ID        = Guid.NewGuid();
                loadFormat.ProductID = viewModel.ProductID;
                _context.Add(loadFormat);
                await _context.SaveChangesAsync();

                //  Populate Format Types

                var loadFormatId = loadFormat.ID;
                PopulateFormatTypes(loadFormatId);
                return(RedirectToAction("Index", new { productId = viewModel.ProductID }));
            }
            var list = (from value in values
                        select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            viewModel.FileTypeList = new SelectList(list, "Value", "Text");
            return(View(viewModel));
        }
示例#2
0
        // GET: LoadFormats/Edit/5
        public async Task <IActionResult> Edit(Guid?Id)
        {
            var loadFormat = await _context.LoadFormats.SingleOrDefaultAsync(m => m.ID == Id);

            if (loadFormat == null)
            {
                return(NotFound());
            }

            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));

            var list = (from value in values
                        select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            LoadFormatViewModel viewModel = new LoadFormatViewModel
            {
                LoadFormat   = loadFormat,
                FileTypeList = new SelectList(list, "Value", "Text", loadFormat.UploadFileType)
            };

            return(View(viewModel));
        }
示例#3
0
        // GET: LoadFormats/Create
        public IActionResult Create(Guid productId)
        {
            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));
            var         list   = (from value in values
                                  select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            LoadFormatViewModel viewModel = new LoadFormatViewModel
            {
                ProductID    = productId,
                FileTypeList = new SelectList(list, "Value", "Text")
            };

            return(View(viewModel));
        }
示例#4
0
        public async Task <IActionResult> Edit(LoadFormatViewModel viewModel)
        {
            FileTypes[] values = (FileTypes[])Enum.GetValues(typeof(FileTypes));

            var list = (from value in values
                        select new SelectListItem()
            {
                Value = ((int)value).ToString(),
                Text = value.ToString()
            }).ToList();

            if (ModelState.IsValid)
            {
                LoadFormat loadFormat = new LoadFormat();
                loadFormat = viewModel.LoadFormat;
                try
                {
                    _context.Update(loadFormat);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoadFormatExists(loadFormat.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", new { productId = loadFormat.ProductID }));
            }
            viewModel.FileTypeList = new SelectList(list, "Value", "Text", viewModel.LoadFormat.UploadFileType);
            return(View(viewModel));
        }