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)); } }
public IActionResult Get() { var response = new ListResponse <ShapesDTO>(); try { var result = _shapesLogic.GetAllShapes(); //throw new Exception(); if (result == null) { response.Messages = ResponseMessages.NotFound(); return(NotFound(response)); } response.Messages = ResponseMessages.Success(); response.Model = result.ToList(); return(Ok(response)); } catch (Exception exception) { response.Messages = ResponseMessages.InternalServerError(exception.ToString()); return(StatusCode(500, response)); } }
public async Task <IActionResult> Get(int id) { var response = new EmployeeResponse() { Result = null }; try { var result = await _employeeService.GetEmployeesById(id); if (result == null) { response.Messages = ResponseMessages.NotFound(); return(NotFound(response)); } response.Messages = ResponseMessages.Success(); response.Result = result; return(Ok(response)); } catch (Exception exception) { response.Messages = ResponseMessages.InternalServerError(exception.ToString()); return(StatusCode(500, response)); } }
public IActionResult Get(int id) { var response = new SingleResponse <ShapesDTO>(); try { var result = _shapesLogic.GetShapeById(id); if (result == null) { response.Messages = ResponseMessages.NotFound(); return(NotFound(response)); } response.Messages = ResponseMessages.Success(); response.Model = result; return(Ok(response)); } catch (Exception exception) { response.Messages = ResponseMessages.InternalServerError(exception.ToString()); return(StatusCode(500, response)); } }
public IActionResult CreatePDF([FromQuery] int?[] ids) { var response = new ListResponse <ShapesDTO>(); try { IEnumerable <ShapesDTO> result = null; result = ids.Length > 0 ? _shapesLogic.GetShapesByIds(ids.Cast <int>().ToArray()) : _shapesLogic.GetAllShapes(); var fileList = new List <string>(); var zipFileName = Path.Combine(Directory.GetCurrentDirectory(), @"PDF\" + DateTime.Now.ToFileTime() + ".zip"); if (result.Count() == 0) { response.Messages = ResponseMessages.NotFound(); return(NotFound(response)); } foreach (var shapesDto in result) { var fileName = Path.Combine(Directory.GetCurrentDirectory(), @"PDF\" + DateTime.Now.ToFileTime() + ".pdf"); CreatePDFFileWithZip(shapesDto, fileName); fileList.Add(fileName); } CreateZipFile(zipFileName, fileList); response.Messages = ResponseMessages.CreatedPDF("File has been created at this URL = " + zipFileName); response.Model = result.ToList(); return(Ok(response)); } catch (Exception exception) { response.Messages = ResponseMessages.InternalServerError(exception.ToString()); return(StatusCode(500, response)); } }
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)); } }