Esempio n. 1
0
        public async Task <ActionResult> CreateUOM(AddUOMViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(UnitOfMeasures), new { id = request.UomTypeId }));
            }
            try
            {
                var addUOMRequest = new AddUnitOfMeasureRequest {
                    UnitOfMeasureTypeId = request.UomTypeId, Name = request.Name, Description = request.Description, Grammage = request.Grammage, PackSize = request.PackSize, PalletSize = request.PalletSize
                };
                var result = await _unitOfMeasureService.Create(addUOMRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(UnitOfMeasures), new { id = request.UomTypeId }));
                }
                Alert($"Unit Of Measure Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(UnitOfMeasures), new { id = request.UomTypeId }));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(UnitOfMeasures), new { id = request.UomTypeId }));
            }
        }
Esempio n. 2
0
        public async Task <ServiceResponse <UnitOfMeasure> > Create(AddUnitOfMeasureRequest request)
        {
            try
            {
                var uomType = await _uomTypeService.FindByIdInclusive(request.UnitOfMeasureTypeId, x => x.Include(p => p.UnitOfMeasures));

                if (!uomType.Success)
                {
                    return(new ServiceResponse <UnitOfMeasure>($"The unit of measure type does not exist"));
                }

                if (uomType.Data.UnitOfMeasures.Count > 0 && uomType.Data.UnitOfMeasures.Any(x => x.Name.ToLower().Equals(request.Name.ToLower())))
                {
                    return(new ServiceResponse <UnitOfMeasure>($"The unit of measure already exist exist"));
                }

                var unitOfMeasure = new UnitOfMeasure
                {
                    Name                = request.Name,
                    Code                = GenerateCode(8),
                    Description         = request.Description,
                    UnitOfMeasureTypeId = uomType.Data.Id,
                    Grammage            = request.Grammage,
                    PackSize            = request.PackSize,
                    PalletSize          = request.PalletSize
                };
                var exist = await _baseRepository.GetByIdAndCode(unitOfMeasure.Id, unitOfMeasure.Code);

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

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

                //uomType.Data.UnitOfMeasures.Add(unitOfMeasure);

                await _baseRepository.Create(unitOfMeasure);

                return(new ServiceResponse <UnitOfMeasure>(unitOfMeasure));
            }
            catch (Exception ex)
            {
                return(new ServiceResponse <UnitOfMeasure>($"An Error Occured While Creating The Unit Of Measure. {ex.Message}"));
            }
        }