public IActionResult Edit(EditCatalogViewModel model) { if (ModelState.IsValid) { try { CatalogDTO сatalogDTO = new CatalogDTO { Id = model.Id, Name = model.Name, Info = model.Info, ProviderId = model.ProviderId }; _сatalogService.EditСatalog(сatalogDTO); string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; _logger.LogInformation($"{DateTime.Now.ToString()}: User {currentUserId} edited catalog {model.Id}"); return(RedirectToAction("Index", new { providerId = model.ProviderId })); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}"); } } return(View(model)); }
public IActionResult Put(CatalogModel model) { try { _сatalogService.EditСatalog(ConvertCatalogModelToCatalogDTO(model)); string currentEmail = this.User.FindFirst(ClaimTypes.Name).Value; string userId = _userHelper.GetUserId(currentEmail); if (userId == null) { return(NotFound("User not found")); } _logger.LogInformation($"[{DateTime.Now.ToString()}]:[catalog/put]:[info:edit catalog {model.Id}]:[user:{userId}]"); return(Ok(model)); } catch (ValidationException ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[catalog/put]:[error:{ex.Property}, {ex.Message}]"); return(BadRequest(ex.Message)); } catch (Exception ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[catalog/put]:[error:{ex}]"); return(BadRequest()); } }