public CalificationUser create(CalificationUser calificationUser)
        {
            foodForAllContext.CalificationUser.Add(calificationUser);
            foodForAllContext.SaveChanges();

            int star = starByIdUser(calificationUser.IdUser);

            userService.updateStarById(calificationUser.IdUser, star);

            return(calificationUser);
        }
        public CalificationUser destroyById(int id)
        {
            CalificationUser calificationUser = (from cu in foodForAllContext.CalificationUser where cu.Id == id select cu).FirstOrDefault();

            foodForAllContext.CalificationUser.Remove(calificationUser);
            foodForAllContext.SaveChanges();

            int star = starByIdUser(calificationUser.IdUser);

            userService.updateStarById(calificationUser.IdUser, star);

            calificationUser = findById(id);

            return(calificationUser);
        }
        public IActionResult findByIdUserAndIdUserCalification([FromHeader(Name = "Authorization")] string token, int idUser, 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)
                    {
                        CalificationUser calificationUser = calificationUserService.findByIdUserAndIdUserCalification(idUser, idUserCalification);

                        if (calificationUser != 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
                            {
                                calificationUser = calificationUser,
                                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] CalificationUser calificationUser)
        {
            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(calificationUser.IdUser.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Usuario es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(calificationUser.IdUserCalification.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "El Id del Usuario Clasificador es requerido.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else if (string.IsNullOrEmpty(calificationUser.Calification.ToString()))
                        {
                            return(Ok(new
                            {
                                message = "La Clasificación es requerida.",
                                statusCode = HttpStatusCode.NoContent
                            }));
                        }
                        else
                        {
                            calificationUser = calificationUserService.create(calificationUser);

                            if (calificationUser.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
                }));
            }
        }
        public CalificationUser findByIdUserAndIdUserCalification(int idUser, int idUserCalification)
        {
            CalificationUser calificationUser = (from cu in foodForAllContext.CalificationUser where cu.IdUser == idUser && cu.IdUserCalification == idUserCalification select cu).FirstOrDefault();

            return(calificationUser);
        }
        public CalificationUser findById(int id)
        {
            CalificationUser calificationUser = (from cu in foodForAllContext.CalificationUser where cu.Id == id select cu).FirstOrDefault();

            return(calificationUser);
        }