예제 #1
0
        public IActionResult Post([FromBody] ShapesRequest request)
        {
            var response = new SingleResponse <ShapesDTO>();

            try
            {
                if (request == null)
                {
                    response.Messages = ResponseMessages.BadRequest();
                    return(NotFound(response));
                }
                if (!ModelState.IsValid)
                {
                    response.Messages = ResponseMessages.ModelValidate(ModelState);
                    return(UnprocessableEntity(response));
                }

                var result = _shapesLogic.AddShape(request);

                response.Messages = ResponseMessages.Created();
                response.Model    = result;
                return(CreatedAtRoute("GetShapeByid",
                                      new { id = result.ShapeId },
                                      response));
            }
            catch (Exception exception)
            {
                response.Messages = ResponseMessages.InternalServerError(exception.ToString());
                return(StatusCode(500, response));
            }
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] EmployeeRequestDTO model)
        {
            var response = new EmployeeResponse()
            {
                Result = null
            };

            try
            {
                if (model == null)
                {
                    response.Messages = ResponseMessages.BadRequest();
                    return(NotFound(response));
                }

                var res = new EmployeeValidator();
                if (!ModelState.IsValid)
                {
                    response.Messages = ResponseMessages.ModelValidate(ModelState);
                    return(UnprocessableEntity(response));
                }

                var result = await _employeeService.AddEmployee(model);

                response.Messages = ResponseMessages.Created();
                response.Result   = result;
                return(CreatedAtRoute("GetEmployees",
                                      new { id = result.EmployeeId },
                                      response));
            }
            catch (Exception exception)
            {
                response.Messages = ResponseMessages.InternalServerError(exception.ToString());
                return(StatusCode(500, response));
            }
        }