Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Model,Name,ImagePath")] ServisDevice servisDevice, int?id)
        {
            if (ModelState.IsValid)
            {
                Series series = _context.BrandSeries.FirstOrDefault(s => s.Id == id);


                if (series != null)
                {
                    series.ServisDevices = new List <ServisDevice>();
                    series.ServisDevices.Add(servisDevice);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", new { id = id }));
                }
            }
            else
            {
                ViewBag.SeriesId   = id;
                ViewBag.SeriesName = _context.BrandSeries.FirstOrDefault(b => b.Id == id)?.Name;
                return(View("Create", servisDevice));
            }



            return(View(servisDevice));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SeriesId,Model,Name,ImagePath,Type")] ServisDevice servisDevice, string imguploader)
        {
            string newImage = HttpContext.Request.Form["imguploader"];

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

            if (!String.IsNullOrEmpty(newImage))
            {
                servisDevice.ImagePath = newImage;
            }

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