public CalificationStock create(CalificationStock calificationStock) { foodForAllContext.CalificationStock.Add(calificationStock); foodForAllContext.SaveChanges(); int star = starByIdStock(calificationStock.IdStock); stockService.updateStarById(calificationStock.IdStock, star); return(calificationStock); }
public CalificationStock destroyById(int id) { CalificationStock calificationStock = (from cs in foodForAllContext.CalificationStock where cs.Id == id select cs).FirstOrDefault(); foodForAllContext.CalificationStock.Remove(calificationStock); foodForAllContext.SaveChanges(); int star = starByIdStock(calificationStock.IdStock); stockService.updateStarById(calificationStock.IdStock, star); calificationStock = findById(id); return(calificationStock); }
public CalificationStock findByIdStockAndIdUserCalification(int idStock, int idUserCalification) { CalificationStock calificationStock = (from cs in foodForAllContext.CalificationStock where cs.IdStock == idStock && cs.IdUserCalification == idUserCalification select cs).FirstOrDefault(); return(calificationStock); }
public CalificationStock findById(int id) { CalificationStock calificationStock = (from cs in foodForAllContext.CalificationStock where cs.Id == id select cs).FirstOrDefault(); return(calificationStock); }
public IActionResult findByIdStockAndIdUserCalification([FromHeader(Name = "Authorization")] string token, int idStock, int idUserCalification) { try { if (string.IsNullOrEmpty(token)) { return(Ok(new { message = "El Token es requerido.", statusCode = HttpStatusCode.NoContent })); } else { string host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); Token tokenExisting = tokenService.findByToken(token, host); if (tokenExisting != null) { CalificationStock calificationStock = calificationStockService.findByIdStockAndIdUserCalification(idStock, idUserCalification); if (calificationStock != null) { EventLog eventLog = new EventLog(); eventLog.IdUser = tokenExisting.IdUser; eventLog.IdEventLogType = 1; eventLog.Host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); eventLog.HttpMethod = ControllerContext.HttpContext.Request.Method; eventLog.Controller = ControllerContext.ActionDescriptor.ControllerName; eventLog.Method = ControllerContext.ActionDescriptor.ActionName; eventLogService.create(eventLog); return(Ok(new { calificationStock = calificationStock, statusCode = HttpStatusCode.OK })); } else { return(Ok(new { message = "El Stock no existe.", statusCode = HttpStatusCode.NotFound })); } } else { return(Ok(new { message = "Token no permitido.", statusCode = HttpStatusCode.Forbidden })); } } } catch (Exception exception) { EventLog eventLog = new EventLog(); eventLog.IdEventLogType = 2; eventLog.Host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); eventLog.HttpMethod = ControllerContext.HttpContext.Request.Method; eventLog.Controller = ControllerContext.ActionDescriptor.ControllerName; eventLog.Method = ControllerContext.ActionDescriptor.ActionName; eventLog.Message = exception.InnerException != null ? exception.InnerException.Message : exception.Message; eventLogService.create(eventLog); return(Ok(new { message = "Upps!!, tenemos un problema, intentalo nuevamente.", statusCode = HttpStatusCode.InternalServerError })); } }
public IActionResult create([FromHeader(Name = "Authorization")] string token, [FromBody] CalificationStock calificationStock) { try { if (string.IsNullOrEmpty(token)) { return(Ok(new { message = "El Token es requerido.", statusCode = HttpStatusCode.NoContent })); } else { string host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); Token tokenExisting = tokenService.findByToken(token, host); if (tokenExisting != null) { if (string.IsNullOrEmpty(calificationStock.IdStock.ToString())) { return(Ok(new { message = "El Id del Stock es requerido.", statusCode = HttpStatusCode.NoContent })); } else if (string.IsNullOrEmpty(calificationStock.IdUserCalification.ToString())) { return(Ok(new { message = "El Id del Usuario Clasificador es requerido.", statusCode = HttpStatusCode.NoContent })); } else if (string.IsNullOrEmpty(calificationStock.Calification.ToString())) { return(Ok(new { message = "La Clasificación es requerida.", statusCode = HttpStatusCode.NoContent })); } else { calificationStock = calificationStockService.create(calificationStock); if (calificationStock.Id != 0) { EventLog eventLog = new EventLog(); eventLog.IdUser = tokenExisting.IdUser; eventLog.IdEventLogType = 1; eventLog.Host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); eventLog.HttpMethod = ControllerContext.HttpContext.Request.Method; eventLog.Controller = ControllerContext.ActionDescriptor.ControllerName; eventLog.Method = ControllerContext.ActionDescriptor.ActionName; eventLogService.create(eventLog); return(Ok(new { message = "Calificación Agregado.", statusCode = HttpStatusCode.Created })); } else { return(Ok(new { message = "La Calificación no se pudo agregar, intentalo nuevamente.", statusCode = HttpStatusCode.NotFound })); } } } else { return(Ok(new { message = "Token no permitido.", statusCode = HttpStatusCode.Forbidden })); } } } catch (Exception exception) { EventLog eventLog = new EventLog(); eventLog.IdEventLogType = 2; eventLog.Host = Request.HttpContext.Connection.RemoteIpAddress.ToString(); eventLog.HttpMethod = ControllerContext.HttpContext.Request.Method; eventLog.Controller = ControllerContext.ActionDescriptor.ControllerName; eventLog.Method = ControllerContext.ActionDescriptor.ActionName; eventLog.Message = exception.InnerException != null ? exception.InnerException.Message : exception.Message; eventLogService.create(eventLog); return(Ok(new { message = "Upps!!, tenemos un problema, intentalo nuevamente.", statusCode = HttpStatusCode.InternalServerError })); } }