Exemple #1
0
        public IActionResult Update(ChartTypeDTO chartTypeDto, int Id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }

            else
            {
                IDataResult <ChartType> dataResult = _service.GetById(Id);

                if (dataResult == null)
                {
                    return(BadRequest(dataResult.Message));
                }

                else
                {
                    mapper = ChartTypeMapping.GetMapper().CreateMapper();

                    ChartType chartType = mapper.Map <ChartTypeDTO, ChartType>(chartTypeDto);

                    IResult result = _service.Update(chartType);

                    if (result.Success)
                    {
                        return(Ok(result.Message));
                    }

                    return(BadRequest(result.Message));
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddAsync(ChartTypeDTO charTypeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }

            else
            {
                mapper = ChartTypeMapping.GetMapper().CreateMapper();

                ChartType chartType = mapper.Map <ChartTypeDTO, ChartType>(charTypeDto);

                IResult result = await _service.AddAsync(chartType);

                if (result.Success)
                {
                    return(Ok(result.Message));
                }
                return(BadRequest(result.Message));
            }
        }