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)); } }