public async Task <ActionResult> Create(AddCatalogViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var catalogRequest = new AddCatalogRequest
                {
                    Name          = request.Name,
                    Description   = request.Description,
                    EffectiveDate = request.EffectiveDate,
                    EndDate       = request.EndDate,
                    EntityId      = request.EntityId,
                    Published     = request.Published
                };

                var result = await _catalogService.Create(catalogRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
                Alert($"Catalog Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
Exemple #2
0
        public IActionResult Add(AddCatalogViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    CatalogDTO сatalogDTO = new CatalogDTO()
                    {
                        Info       = model.Info,
                        Name       = model.Name,
                        ProviderId = model.ProviderId
                    };

                    _сatalogService.AddСatalog(сatalogDTO);

                    string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                    _logger.LogInformation($"{DateTime.Now.ToString()}: User {currentUserId} added new catalog");

                    return(RedirectToAction("Index", new { model.ProviderId }));
                }
                catch (ValidationException ex)
                {
                    ModelState.AddModelError(ex.Property, ex.Message);
                    _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}");
                }
            }
            return(View(model));
        }
        // GET: Catalogs/Create
        public async Task <ActionResult> Create()
        {
            var catalog   = new AddCatalogViewModel();
            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;
            return(View(catalog));
        }