Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        public async Task <ServiceResponse <Catalog> > Create(AddCatalogRequest request)
        {
            try
            {
                var catalog = new Catalog
                {
                    Code          = $"CTLG{_codeGeneratorService.GenerateRandomString(8)}",
                    Description   = request.Description,
                    Name          = request.Name,
                    EffectiveDate = request.EffectiveDate,
                    EndDate       = request.EndDate,
                    EntityId      = request.EntityId,
                    Published     = request.Published
                };

                var exist = await _baseRepository.GetByIdAndCode(catalog.Id, catalog.Code);

                if (exist != null)
                {
                    return(new ServiceResponse <Catalog>($"A Catalog With the Provided Code and or Id Already Exist"));
                }

                var exist2 = await _baseRepository.FindOneByConditions(x => x.Name.ToLower().Equals(catalog.Name.ToLower()));

                if (exist2 != null)
                {
                    return(new ServiceResponse <Catalog>($"A Catalog With the Provided Name Already Exist"));
                }

                await _baseRepository.Create(catalog);

                return(new ServiceResponse <Catalog>(catalog));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <Catalog>($"An Error Occured While Creating the Catalog. {ex.Message}"));
            }
        }