Example #1
0
        public IActionResult CreateCategory(CategoryForCreationDto category)
        {
            if (!ModelState.IsValid || category == null)
            {
                return(BadRequest(ModelState));
            }

            var categoryToSave = new Category();

            AutoMapper.Mapper.Map(category, categoryToSave);

            var imgUrl = _s3Service.UploadFile(category.Image);

            if (!string.IsNullOrEmpty(imgUrl))
            {
                categoryToSave.ImgUrl = imgUrl;
            }

            _viLabRepository.AddCategory(categoryToSave);


            if (!_viLabRepository.Save())
            {
                return(BadRequest($"failed to create category {category.Name}"));
            }

            return(Ok());
        }
Example #2
0
        public IActionResult CreateSubcategory([FromBody] SubcategoryForCreationDto subcategory)
        {
            if (!ModelState.IsValid || subcategory == null)
            {
                return(BadRequest(ModelState));
            }

            var subcategoryToSave = new Subcategory();

            AutoMapper.Mapper.Map(subcategory, subcategoryToSave);

            _vilabRepository.AddSubcategory(subcategoryToSave);

            if (!_vilabRepository.Save())
            {
                return(BadRequest($"failed to create subcategory {subcategory.Name} "));
            }

            return(Ok());
        }
Example #3
0
        public IActionResult CreateCase(CaseForCreationDto caseForCreationDto)
        {
            if (!ModelState.IsValid || caseForCreationDto == null)
            {
                return(BadRequest(ModelState));
            }

            caseForCreationDto.BeforeImgUrl = caseForCreationDto.BeforeImage != null?_s3Service.UploadFile(caseForCreationDto.BeforeImage) : string.Empty;

            caseForCreationDto.AfterImgUrl = caseForCreationDto.AfterImage != null?_s3Service.UploadFile(caseForCreationDto.AfterImage) : string.Empty;

            var caseToSave = new Case();

            AutoMapper.Mapper.Map(caseForCreationDto, caseToSave);

            _vilabRepository.AddCase(caseToSave);

            if (!_vilabRepository.Save())
            {
                return(BadRequest($"Failed to create case {caseForCreationDto.Name}"));
            }

            return(Ok());
        }