Esempio n. 1
0
        public async Task <ServiceResponse <EntityType> > Create(AddEntityTypeRequest request)
        {
            try
            {
                var tier = new EntityType
                {
                    Code        = $"ETTP{_codeGen.GenerateRandomString(8)}",
                    Description = request.Description,
                    Name        = request.Name,
                };

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

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

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

                if (exist2 != null)
                {
                    return(new ServiceResponse <EntityType>($"An Entity Type With the Provided Name Already Exist"));
                }

                await _baseRepository.Create(tier);

                return(new ServiceResponse <EntityType>(tier));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <EntityType>($"An Error Occured While Creating The Entity Type. {ex.Message}"));
            }
        }
        public async Task <ActionResult> Create(AddEntityTypeViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                var addTierRequest = new AddEntityTypeRequest {
                    Name = request.Name, Description = request.Description
                };
                var result = await _entityTypeService.Create(addTierRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(Create)));
                }
                Alert($"Tier 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(RedirectToAction(nameof(Create)));
            }
        }