Пример #1
0
        public async Task <IActionResult> Update(int demandId, [FromBody] DemandRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _demandService.Update(demandId, request);

            if (!result.IsSuccessed)
            {
                return(BadRequest(result.Message));
            }
            return(Ok());
        }
Пример #2
0
        public async Task <ApiResponse <string> > Create(DemandRequest request)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                return(new ApiErrorResponse <string>(ConstantStrings.emptyNameFieldError));
            }
            var demand = new Demand()
            {
                Name = request.Name
            };

            _db.Demands.Add(demand);
            await _db.SaveChangesAsync();

            return(new ApiSuccessResponse <string>(ConstantStrings.addSuccessfully));
        }
Пример #3
0
        public async Task <ApiResponse <string> > Update(int demandId, DemandRequest request)
        {
            var demandFromDb = await _db.Demands.FindAsync(demandId);

            if (demandFromDb == null)
            {
                return(new ApiErrorResponse <string>(ConstantStrings.FindByIdError(demandId)));
            }
            if (string.IsNullOrEmpty(request.Name))
            {
                return(new ApiErrorResponse <string>(ConstantStrings.emptyNameFieldError));
            }
            demandFromDb.Name = request.Name;
            _db.Demands.Update(demandFromDb);
            await _db.SaveChangesAsync();

            return(new ApiSuccessResponse <string>(ConstantStrings.editSuccessfully));
        }