Пример #1
0
        public async Task <ServiceResponse <PackagingType> > Create(AddPackagingTypeRequest request)
        {
            try
            {
                var packaging = await _packagingTypeService.FindByIdInclusive(request.PackagingId, x => x.Include(p => p.PackagingTypes));

                if (!packaging.Success)
                {
                    return(new ServiceResponse <PackagingType>($"The Packaging type does not exist"));
                }

                if (packaging.Data.PackagingTypes.Count > 0 && packaging.Data.PackagingTypes.Any(x => x.Name.ToLower().Equals(request.Name.ToLower())))
                {
                    return(new ServiceResponse <PackagingType>($"The Packaging already exist exist"));
                }

                var packagingType = new PackagingType
                {
                    Name        = request.Name,
                    Code        = GenerateCode(8),
                    Description = request.Description,
                    PackagingId = packaging.Data.Id
                };
                var exist = await _baseRepository.GetByIdAndCode(packagingType.Id, packagingType.Code);

                if (exist != null)
                {
                    return(new ServiceResponse <PackagingType>($"A Packaging Type With the Provided Code and or Id Already Exist"));
                }
                var exist2 = await _baseRepository.FindOneByConditions(x => x.Name.ToLower().Equals(packagingType.Name.ToLower()));

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

                await _baseRepository.Create(packagingType);

                return(new ServiceResponse <PackagingType>(packagingType));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <PackagingType>($"An Error Occured While Creating The Packaging Type. {ex.Message}"));
            }
        }
Пример #2
0
        //PACKAGING TYPE SECTION
        public async Task <ActionResult> PackagingTypes(Guid id)
        {
            var packagingTypeList = new List <ListPackagingTypeViewModel>();

            try
            {
                var result = await _packagingService.FindByIdInclusive(id, x => x.Include(p => p.PackagingTypes));

                if (!result.Success)
                {
                    Alert($"Error! {result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View(packagingTypeList));
                }

                ViewBag.Packaging = result.Data;

                if (result.Data.PackagingTypes.Count > 0)
                {
                    foreach (var item in result.Data.PackagingTypes)
                    {
                        packagingTypeList.Add(new ListPackagingTypeViewModel
                        {
                            Code            = item.Code,
                            DateCreated     = item.CreatedAt,
                            DateLastUpdated = item.LastUpdated,
                            Description     = item.Description,
                            Id            = item.Id,
                            Name          = item.Name,
                            PackagingName = result.Data.Name
                        });
                    }
                }
                return(View(packagingTypeList));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View(packagingTypeList));
            }
        }