public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Error)));
            }

            var batch = await _service.GetByIdAsync(id.Value);

            if (batch == null)
            {
                return(RedirectToAction(nameof(Error)));
            }

            var products = await _prodService.GetAllAsync();

            ViewBag.Products = new SelectList(products, "Id", "Name");

            var providers = await _provService.GetAllAsync();

            ViewBag.Providers = new SelectList(providers, "Id", "Name");

            return(View(batch));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetByIdAsync([Required] int id)
        {
            var prefix = "[GetByIdAsync]";

            _logger.LogInformation($"{prefix} Executing action");

            var batch = await _service.GetByIdAsync(id);

            if (batch == null)
            {
                _logger.LogWarning($"{prefix} Batch with id {id} not found");
                return(NotFound());
            }

            _logger.LogInformation($"{prefix} Returning batch with id {id}");
            return(Ok(batch));
        }