コード例 #1
0
        public async Task <IActionResult> Edit(int id, Tool tool)
        {
            if (id != tool.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    tool = Trim(tool);
                    if (CanEdit(tool))
                    {
                        ModelState.AddModelError(string.Empty, "Narzędzie o takim adresie MAC już istnieje");
                        return(View(tool));
                    }
                    else
                    {
                        _context.Update(tool);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ToolExists(tool.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tool));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, Hub hub)
        {
            if (id != hub.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    hub = Trim(hub);
                    if (CanEdit(hub) == true)
                    {
                        ModelState.AddModelError(string.Empty, "Koncentrator o takim adresie IP już istnieje");
                        return(View(hub));
                    }
                    else
                    {
                        _context.Update(hub);
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HubExists(hub.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hub));
        }