Exemple #1
0
        public async Task <IActionResult> AddCategory(SubCategoryAddRequest model)
        {
            Response oR = new Response();

            try
            {
                if (!ModelState.IsValid)
                {
                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.ValidationsFailed;
                    oR.Data    = GetModelErrors(ModelState);

                    return(BadRequest(oR));
                }

                if (!await _service.ExistsName(model.CategoryId, model.Name))
                {
                    ModelState.AddModelError("Name", Messages.ResourceNameAlreadyExists);

                    oR.Status  = StatusCodes.Status400BadRequest;
                    oR.Message = Messages.ValidationsFailed;
                    oR.Data    = GetModelErrors(ModelState);

                    return(BadRequest(oR));
                }

                var oCategory = await _service.Add(model);

                if (oCategory != null)
                {
                    oR.Status = StatusCodes.Status201Created;
                    oR.Data   = oCategory;

                    return(CreatedAtAction(nameof(GetById), new { id = oCategory.Id }, oR));
                }
                else
                {
                    oR.Status  = StatusCodes.Status500InternalServerError;
                    oR.Message = Messages.InternalServerError;

                    return(StatusCode(StatusCodes.Status500InternalServerError, oR));
                }
            }
            catch (Exception ex)
            {
                oR.Status  = StatusCodes.Status500InternalServerError;
                oR.Message = Messages.InternalServerError;

                return(StatusCode(StatusCodes.Status500InternalServerError, oR));
            }
        }
        public async Task <IActionResult> Create(SubCategoryCreateDto subCategoryDto)
        {
            if (await _subCategoryService.CheckExists(subCategoryDto.ID))
            {
                return(BadRequest("SubCategory ID already exists!"));
            }
            //var username = User.FindFirst(ClaimTypes.Name).Value;
            //subCategoryIngredientDto.Updated_By = username;
            if (await _subCategoryService.Add(subCategoryDto))
            {
                return(NoContent());
            }

            throw new Exception("Creating the subCategory failed on save");
        }
Exemple #3
0
        public SubCategory Save(SubCategory subCategory)
        {
            SubCategory result;

            subCategory.Category = null;

            if (subCategory.Id > 0)
            {
                SaveFields(subCategory);
                result = _service.Update(subCategory);
            }
            else
            {
                result = _service.Add(subCategory);
            }

            return(result);
        }
Exemple #4
0
 public IActionResult Create([FromBody] SubCategoryModel model)
 {
     _service.Add(model);
     return(Ok(model));
 }
Exemple #5
0
        public async Task <IActionResult> Create([FromBody] SubCategoryModel model)
        {
            await _service.Add(model);

            return(Ok(model));
        }
Exemple #6
0
        public IActionResult Post([FromBody] SubCategory body)
        {
            var entity = _manager.Add(body);

            return(ResponseJson(entity));
        }