Exemple #1
0
        public async Task <IActionResult> PostRestrictionMat([FromBody] RestrictionMatDTO restrictionMatDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var restriction = await restrictionRepository.Add(restrictionMatDTO);

            if (restriction == null)
            {
                return(BadRequest());
            }

            CombinationDTO combination = new CombinationDTO();

            combination.CombinationId     = restriction.combination.CombinationId;
            combination.containedProduct  = restriction.combination.containedProduct.name;
            combination.containingProduct = restriction.combination.containingProduct.name;
            combination.required          = restriction.combination.required;

            RestrictionMat    res_mat = (RestrictionMat)restriction;
            RestrictionMatDTO dto     = new RestrictionMatDTO();

            dto.combination        = combination;
            dto.description        = res_mat.description;
            dto.RestrictionId      = res_mat.RestrictionId;
            dto.containingMaterial = res_mat.containingMaterial.name;
            dto.containedMaterial  = res_mat.containedMaterial.name;

            return(CreatedAtAction("GetRestriction", dto));
        }
Exemple #2
0
        public async Task <Restriction> Add(RestrictionDTO dto)
        {
            Combination combination = await context.Combination.SingleOrDefaultAsync(c => c.containedProduct.name == dto.combination.containedProduct && c.containingProduct.name == dto.combination.containingProduct);

            if (combination == null)
            {
                return(null);
            }

            if (dto is RestrictionDimDTO)
            {
                RestrictionDimDTO res_dim_dto = (RestrictionDimDTO)dto;
                RestrictionDim    res_dim     = new RestrictionDim();
                res_dim.combination = combination;
                res_dim.description = res_dim_dto.description;
                res_dim.x           = res_dim_dto.x;
                res_dim.y           = res_dim_dto.y;
                res_dim.z           = res_dim_dto.z;

                context.Restriction.Add(res_dim);
                await context.SaveChangesAsync();

                return(res_dim);
            }

            if (dto is RestrictionMatDTO)
            {
                RestrictionMatDTO res_mat_dto        = (RestrictionMatDTO)dto;
                RestrictionMat    res_mat            = new RestrictionMat();
                Material          containingMaterial = await context.Material.SingleOrDefaultAsync(m => m.name == res_mat_dto.containingMaterial);

                Material containedMaterial = await context.Material.SingleOrDefaultAsync(m => m.name == res_mat_dto.containedMaterial);

                if (containedMaterial == null)
                {
                    return(null);
                }
                if (containingMaterial == null)
                {
                    return(null);
                }

                res_mat.combination        = combination;
                res_mat.description        = res_mat_dto.description;
                res_mat.containingMaterial = containingMaterial;
                res_mat.containedMaterial  = containedMaterial;

                context.Restriction.Add(res_mat);
                await context.SaveChangesAsync();

                return(res_mat);
            }

            return(null);
        }
Exemple #3
0
        public async Task <IActionResult> GetRestrictions([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <Restriction> restrictions = await productRepository.Restricitons(id);

            if (restrictions == null)
            {
                return(BadRequest());
            }

            List <RestrictionDTO> dtos = new List <RestrictionDTO>();

            foreach (Restriction restriction in restrictions)
            {
                CombinationDTO combination = new CombinationDTO();
                combination.CombinationId     = restriction.combination.CombinationId;
                combination.containedProduct  = restriction.combination.containedProduct.name;
                combination.containingProduct = restriction.combination.containingProduct.name;
                combination.required          = restriction.combination.required;

                if (restriction is RestrictionDim)
                {
                    RestrictionDim    res_dim = (RestrictionDim)restriction;
                    RestrictionDimDTO dto     = new RestrictionDimDTO();
                    dto.combination   = combination;
                    dto.description   = res_dim.description;
                    dto.RestrictionId = res_dim.RestrictionId;
                    dto.x             = res_dim.x;
                    dto.y             = res_dim.y;
                    dto.z             = res_dim.z;
                    dtos.Add(dto);
                }

                if (restriction is RestrictionMat)
                {
                    RestrictionMat    res_mat = (RestrictionMat)restriction;
                    RestrictionMatDTO dto     = new RestrictionMatDTO();
                    dto.combination        = combination;
                    dto.description        = res_mat.description;
                    dto.RestrictionId      = res_mat.RestrictionId;
                    dto.containingMaterial = res_mat.containingMaterial.name;
                    dto.containedMaterial  = res_mat.containedMaterial.name;
                    dtos.Add(dto);
                }
            }

            return(Ok(dtos));
        }
Exemple #4
0
        public async Task <IActionResult> GetRestriction([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var restriction = await restrictionRepository.FindById(id);

            if (restriction == null)
            {
                return(NotFound());
            }

            CombinationDTO combination = new CombinationDTO();

            combination.CombinationId     = restriction.combination.CombinationId;
            combination.containedProduct  = restriction.combination.containedProduct.name;
            combination.containingProduct = restriction.combination.containingProduct.name;
            combination.required          = restriction.combination.required;

            if (restriction is RestrictionDim)
            {
                RestrictionDim    res_dim = (RestrictionDim)restriction;
                RestrictionDimDTO dto     = new RestrictionDimDTO();
                dto.combination   = combination;
                dto.description   = res_dim.description;
                dto.RestrictionId = res_dim.RestrictionId;
                dto.x             = res_dim.x;
                dto.y             = res_dim.y;
                dto.z             = res_dim.z;
                return(Ok(dto));
            }

            if (restriction is RestrictionMat)
            {
                RestrictionMat    res_mat = (RestrictionMat)restriction;
                RestrictionMatDTO dto     = new RestrictionMatDTO();
                dto.combination        = combination;
                dto.description        = res_mat.description;
                dto.RestrictionId      = res_mat.RestrictionId;
                dto.containingMaterial = res_mat.containingMaterial.name;
                dto.containedMaterial  = res_mat.containedMaterial.name;
                return(Ok(dto));
            }

            return(BadRequest());
        }
Exemple #5
0
        public IEnumerable <RestrictionDTO> GetRestriction()
        {
            List <RestrictionDTO> dtos = new List <RestrictionDTO>();

            foreach (Restriction restriction in restrictionRepository.FindAll())
            {
                CombinationDTO combination = new CombinationDTO();
                combination.CombinationId     = restriction.combination.CombinationId;
                combination.containedProduct  = restriction.combination.containedProduct.name;
                combination.containingProduct = restriction.combination.containingProduct.name;
                combination.required          = restriction.combination.required;

                if (restriction is RestrictionDim)
                {
                    RestrictionDim    res_dim = (RestrictionDim)restriction;
                    RestrictionDimDTO dto     = new RestrictionDimDTO();
                    dto.combination   = combination;
                    dto.description   = res_dim.description;
                    dto.RestrictionId = res_dim.RestrictionId;
                    dto.x             = res_dim.x;
                    dto.y             = res_dim.y;
                    dto.z             = res_dim.z;
                    dtos.Add(dto);
                }

                if (restriction is RestrictionMat)
                {
                    RestrictionMat    res_mat = (RestrictionMat)restriction;
                    RestrictionMatDTO dto     = new RestrictionMatDTO();
                    dto.combination        = combination;
                    dto.description        = res_mat.description;
                    dto.RestrictionId      = res_mat.RestrictionId;
                    dto.containingMaterial = res_mat.containingMaterial.name;
                    dto.containedMaterial  = res_mat.containedMaterial.name;
                    dtos.Add(dto);
                }
            }
            return(dtos);
        }