public IHttpActionResult PutServerEvent(int id, ServerEvent serverEvent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != serverEvent.ServerEventId)
            {
                return(BadRequest());
            }

            serverEvent.UpTimes = serverEvent.UpTimes.HasValue ? serverEvent.UpTimes.Value.Date : serverEvent.UpTimes;

            Context.Entry(serverEvent).State = EntityState.Modified;

            try
            {
                Context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServerEventExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutRestaurant(int id, Restaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurant.RestaurantId)
            {
                return(BadRequest());
            }

            Context.Entry(restaurant).State = EntityState.Modified;

            try
            {
                Context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PostAuthorization(string ipAddress, DateTime upTimes)
        {
            DateTime upTimeDate = upTimes.Date;

            try
            {
                if (!IpAddressRestriction.IsValid(Context, ipAddress, out RestaurantId))
                {
                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Addresse Ip invalide"
                    }));
                }

                if (!TwoWeekRestartRestriction.CheckLastServerUpTimes(Context, RestaurantId, upTimeDate))
                {
                    Context.ServerEvents.Add(new ServerEvent()
                    {
                        Date         = OperationDateTime,
                        RestaurantId = RestaurantId,
                        Event        = Event.RedemarrageOK,
                        Detail       = "Dernier redémarrage Serveur",
                        UpTimes      = upTimeDate
                    });

                    Context.SaveChanges();
                }

                if (!TwoWeekRestartRestriction.IsValid(Context, RestaurantId, OperationDateTime))
                {
                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Le dernier redémarrage est inferieur a 15 jours"
                    }));
                }

                if (!MaxRestartRestriction.IsValid(Context, OperationDateTime))
                {
                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Vous avez depasser le nombre de redémarrage authorisé"
                    }));
                }

                if (!StartingDateRestriction.IsValid(Context, OperationDateTime))
                {
                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Impossible d'executer un redémarrage aujourd'hui"
                    }));
                }

                if (DeploiementDateRestriction.CheckDeploiementDate(RestaurantId, OperationDateTime))
                {
                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Impossible d'executer un redémarrage aujourd'hui, un deploiement est prevu"
                    }));
                }

                if (PriorityRestriction.CheckPriority(Context, RestaurantId))
                {
                    Context.ServerEvents.Add
                    (
                        new ServerEvent()
                    {
                        Date    = OperationDateTime,
                        Event   = Event.DemandeRejete,
                        Detail  = "Demande de redémarrage non prioritaire",
                        UpTimes = upTimeDate
                    }
                    );

                    Context.SaveChanges();

                    return(Ok(new AuthorizationModel()
                    {
                        StatusCode = "KO",
                        Detail = "Demande de redémarrage non prioritaire"
                    }));
                }

                return(Ok(new AuthorizationModel()
                {
                    StatusCode = "OK",
                    Detail = "Vous pouvez redémarrer la machine distante"
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new AuthorizationModel()
                {
                    StatusCode = "ERREUR",
                    Detail = ex.StackTrace
                }));
            }
        }