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 ActionResult Edit(int?id) { _logger.LogInformation($"{DateTime.Now.ToString()}: Processing request Catalog/Edit"); try { CatalogDTO сatalogDTO = _сatalogService.GetСatalog(id); if (сatalogDTO == null) { throw new ValidationException(_sharedLocalizer["CatalogNoFind"], ""); } var provider = new EditCatalogViewModel() { Id = сatalogDTO.Id, Info = сatalogDTO.Info, Name = сatalogDTO.Name, ProviderId = сatalogDTO.ProviderId }; return(View(provider)); } catch (ValidationException ex) { _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}"); return(Content(ex.Message)); } }
public IActionResult Put([FromBody] EditCatalogViewModel model) { var newCatalog = mapper.Map <Catalog>(model); var res = repo.Update(newCatalog); return(Ok(res)); }
public async Task <ActionResult> Edit(Guid id, EditCatalogViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } if (!id.Equals(request.CatalogId)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } try { var catalogUpdateRequest = new UpdateCatalogRequest { CatalogId = request.CatalogId, Name = request.Name, Description = request.Description, EffectiveDate = request.EffectiveDate, EndDate = request.EndDate, EntityId = request.EntityId, Published = request.Published }; var result = await _catalogService.Update(id, catalogUpdateRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } Alert($"Catalog Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View()); } }
// GET: Catalogs/Edit/5 public async Task <ActionResult> Edit(Guid id) { var catalog = new EditCatalogViewModel(); try { var entities = new List <EntityResource>(); var suppliers = await _supplierService.FindAll(); if (!suppliers.Success) { Alert($"{suppliers.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); } else { foreach (var supplier in suppliers.Data) { entities.Add(new EntityResource { Id = supplier.Id, Name = supplier.Name }); } } var merchants = await _merchantService.FindAll(); if (!merchants.Success) { Alert($"{merchants.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); } else { foreach (var merchant in merchants.Data) { entities.Add(new EntityResource { Id = merchant.Id, Name = merchant.Name }); } } ViewBag.Entities = entities; var result = await _catalogService.FindById(id); if (!result.Success) { Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(catalog)); } catalog.CatalogId = result.Data.Id; catalog.Name = result.Data.Name; catalog.EffectiveDate = result.Data.EffectiveDate; catalog.EndDate = result.Data.EndDate; catalog.Published = result.Data.Published; catalog.Description = result.Data.Description; catalog.EntityId = result.Data.EntityId; return(View(catalog)); } catch (Exception ex) { Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(catalog)); } }