예제 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,ImageLogoPath,Description")] DeviceBrand deviceBrand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(deviceBrand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(deviceBrand));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Name,Description,DeviceBrandId")] Series series, int?id)
        {
            series.ServisDevices = new List <ServisDevice>();
            ViewBag.BrandID      = id;
            ViewBag.BrandName    = _context.DeviceBrands.FirstOrDefault(b => b.Id == id)?.Name;
            if (ModelState.IsValid)
            {
                DeviceBrand brand = _context.DeviceBrands.FirstOrDefault(b => b.Id == id);
                brand.SeriesList = new List <Series>();

                brand.SeriesList.Add(series);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new{ id = id }));
            }
            else
            {
                return(View(series));
            }
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,ImageLogoPath,Description")] DeviceBrand deviceBrand)
        {
            string newImage = HttpContext.Request.Form["imguploader"];



            if (id != deviceBrand.Id)
            {
                return(NotFound());
            }

            if (!String.IsNullOrEmpty(newImage))
            {
                deviceBrand.ImageLogoPath = newImage;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(deviceBrand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DeviceBrandExists(deviceBrand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View(deviceBrand));
        }