示例#1
0
        public IActionResult Update(WidgetTypeDTO widgetTypeDTO, int Id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }
            else
            {
                IDataResult <WidgetType> result = _iWidgetTypeService.GetById(Id);
                if (result == null)
                {
                    return(BadRequest(result.Message));
                }
                else
                {
                    _iMapper = WidgetTypeMapping.GetMapper().CreateMapper();
                    WidgetType widgetType = _iMapper.Map <WidgetTypeDTO, WidgetType>(widgetTypeDTO);

                    IResult updateResult = _iWidgetTypeService.Update(widgetType);

                    if (updateResult.Success)
                    {
                        return(Ok(updateResult.Message));
                    }
                    return(BadRequest(updateResult.Message));
                }
            }
        }
示例#2
0
        public async Task <IActionResult> UpdateAsync(WidgetTypeDTO widgetTypeDTO, int Id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }
            else
            {
                IDataResult <WidgetType> dataResult = await _iWidgetTypeService.FindByIdAsync(Id);

                if (dataResult.Data == null)
                {
                    return(BadRequest(dataResult.Message));
                }
                _iMapper = WidgetTypeMapping.GetMapper().CreateMapper();

                WidgetType widgetType = _iMapper.Map <WidgetTypeDTO, WidgetType>(widgetTypeDTO);

                IResult result = await _iWidgetTypeService.UpdateAsync(widgetType);

                if (result.Success)
                {
                    return(Ok(result.Message));
                }
                return(BadRequest(result.Message));
            }
        }
示例#3
0
        public IActionResult Add(WidgetTypeDTO widgetTypeDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }
            else
            {
                _iMapper = WidgetTypeMapping.GetMapper().CreateMapper();
                WidgetType widgetType = _iMapper.Map <WidgetTypeDTO, WidgetType>(widgetTypeDTO);

                IResult result = _iWidgetTypeService.Add(widgetType);

                if (result.Success)
                {
                    return(Ok(result.Message));
                }
                return(BadRequest(result.Message));
            }
        }
示例#4
0
        public async Task <IActionResult> AddAsync(WidgetTypeDTO widgetTypeDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessage()));
            }
            else
            {
                _iMapper = WidgetTypeMapping.GetMapper().CreateMapper();

                WidgetType widgetType = _iMapper.Map <WidgetTypeDTO, WidgetType>(widgetTypeDTO);

                IResult result = await _iWidgetTypeService.AddAsync(widgetType);

                if (result.Success)
                {
                    return(Ok(result.Message));
                }
                return(BadRequest($"{result.Message} \n Try Again later can be either server error or user error "));
            }
        }