public async Task <IActionResult> Delete(int id) { string usuario = UserTokenOptions.GetClaimTypesNameValue(User.Identity); const string endpointName = nameof(Delete); string header = $"DELETE | {usuario} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.DeleteItem, $"{header} - {MessageLog.Start.Value}"); if (await service.DeleteById(id, usuario)) { logger.LogInformation((int)LogEventEnum.Events.DeleteItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(new { message = MessageSuccess.Delete.Value })); } logger.LogWarning((int)LogEventEnum.Events.DeleteItemNotFound, $"{header} - {MessageError.BadRequest.Value}"); return(BadRequest(new { message = MessageError.BadRequest.Value })); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.DeleteItemError, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <ActionResult <IEnumerable <StatusCompra> > > GetAll() { const string endpointName = nameof(GetAll); string header = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Start.Value}"); IEnumerable <StatusCompra> entities = await service.GetAll(UserTokenOptions.GetClaimTypesNameValue(User.Identity)); if (entities.ToList().Count <= 0) { logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound, $"{header} - {MessageError.NotFound.Value}"); return(NotFound(new { message = MessageError.NotFound.Value })); } logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(entities)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.GetItemError, ex, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <ActionResult <StatusCompra> > Post(StatusCompra entity) { string usuario = UserTokenOptions.GetClaimTypesNameValue(User.Identity); const string endpointName = nameof(Post); string header = $"POST | {usuario} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.InsertItem, $"{header} | {MessageLog.Start.Value}"); entity = await service.Create(entity, usuario); logger.LogInformation((int)LogEventEnum.Events.InsertItem, $"{header} | {MessageLog.Stop.Value}"); return(Ok(entity)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.InsertItemError, $"{header} | {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <ActionResult <Revendedor> > GetById(int id) { const string endpointName = nameof(GetById); string header = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Start.Value}"); Revendedor entity = await service.GetById(id, UserTokenOptions.GetClaimTypesNameValue(User.Identity)); if (entity is null) { logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound, $"{header} - {MessageError.NotFoundSingle.Value}"); return(NotFound(new { message = MessageError.NotFoundSingle.Value })); } logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(entity)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.GetItemError, ex, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <ActionResult <Cashback> > GetCashbackPoints(string cpf) { const string endpointName = nameof(GetCashbackPoints); string header = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Start.Value}"); Cashback cashback = await service.GetCashbackPoints(cpf, UserTokenOptions.GetClaimTypesNameValue(User.Identity)); if (cashback is null) { logger.LogWarning((int)LogEventEnum.Events.GetItem, $"{header} - {MessageError.NotFoundSingle.Value}"); return(NotFound(new { message = MessageError.NotFoundSingle.Value })); } logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(cashback.Body)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.GetItem, ex, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <ActionResult <IEnumerable <HistoricoViewModel> > > GetByTabelaChave(string nomeTabela, int chaveTabela) { const string endpointName = nameof(GetByTabelaChave); string header = $"GET | {UserTokenOptions.GetClaimTypesNameValue(User.Identity)} | {controllerName}: {endpointName}"; try { logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Start.Value}"); IEnumerable <HistoricoViewModel> entities = await service.GetByTabelaChave(nomeTabela, chaveTabela, UserTokenOptions.GetClaimTypesNameValue(User.Identity)); if (entities is null) { logger.LogInformation((int)LogEventEnum.Events.GetItemNotFound, $"{header} - {MessageError.NotFoundSingle.Value}"); return(NotFound(new { message = MessageError.NotFoundSingle.Value })); } logger.LogInformation((int)LogEventEnum.Events.GetItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(entities)); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.GetItemError, ex, $"{header} - {MessageLog.Error.Value} | Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }
public async Task <IActionResult> Put(int id, StatusCompra entity) { string usuario = UserTokenOptions.GetClaimTypesNameValue(User.Identity); const string endpointName = nameof(Put); string header = $"PUT | {usuario} | {controllerName}: {endpointName}"; try { if (id != entity.Id) { logger.LogWarning((int)LogEventEnum.Events.UpdateItemNotFound, $"{MessageError.DifferentIds.Value} - ID Entrada: {id} | ID Objeto: {entity.Id}"); return(BadRequest(new { message = MessageError.DifferentIds.Value })); } logger.LogInformation((int)LogEventEnum.Events.UpdateItem, $"{header} - {MessageLog.Start.Value}"); if (await service.Update(entity, usuario)) { logger.LogInformation((int)LogEventEnum.Events.UpdateItem, $"{header} - {MessageLog.Stop.Value}"); return(Ok(new { message = MessageSuccess.Update.Value })); } logger.LogWarning((int)LogEventEnum.Events.UpdateItemNotFound, $"{header} - {MessageLog.UpdateNotFound.Value} - ID: {id}"); return(NotFound(new { message = MessageError.NotFoundSingle.Value })); } catch (Exception ex) { logger.LogError((int)LogEventEnum.Events.UpdateItemError, ex, $"{header} - {MessageLog.Error.Value} - Exception: {ex.Message}"); return(StatusCode(StatusCodes.Status500InternalServerError, new { message = MessageError.InternalError.Value, error = ex.Message })); } }