/// <summary>
 /// <see cref="INoteManagerService.ConnectUser(string, string)"/>
 /// </summary>
 /// <param name="login"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public UserDTO ConnectUser(string login, string password)
 {
     if (login == null || password == null)
     {
         throw new ArgumentNullException("login or password");
     }
     using (var nme = new NoteManagerEntities())
     {
         var user = from u in nme.User where u.Login == login select u;
         if (user.Count() == 1)
         {
             var u = user.First();
             UserDTO res = new UserDTO(u);
             // Si le password est ok, on renvoie le UserDTO, sinon null;
             return password == res.Password ? res : null;
         }
         else
         {
             var users = nme.User;
             var id = MaxIdUsers(users) + 1;
             User res = new User();
             res.Id = id;
             res.Login = login;
             res.Password = password;
             nme.User.Add(res);
             nme.SaveChanges();
             return new UserDTO(res);
         }
     }
 }
 /// <summary>
 /// <see cref="INoteManagerService.DeleteNote(int)"/>
 /// </summary>
 /// <param name="id"></param>
 public void DeleteNote(int id)
 {
     using (var nme = new NoteManagerEntities())
     {
         var noteToDelete = (from n in nme.Note where n.Id == id select n).FirstOrDefault();
         if (noteToDelete != null)
         {
             nme.Note.Remove(noteToDelete);
             nme.SaveChanges();
         }
     }
 }
        /// <summary>
        /// <see cref="INoteManagerService.UpdateNote(NoteDTO, DateTime)"/>
        /// </summary>
        /// <param name="note"></param>
        /// <param name="dateModification"></param>
        /// <returns></returns>
        public NoteDTO UpdateNote(NoteDTO note, DateTime dateModification)
        {
            Logger logger = new Logger(this.GetType());
            logger.Info("[FONTION UPDATE]");

            if (note == null || dateModification == null)
            {
                throw new ArgumentNullException("UpdateNote : note or dates failed");
            }
            using (var nme = new NoteManagerEntities())
            {
                Note res = nme.Note.Find(note.Id);
                res.Name = note.Name;
                res.Message = note.Message;
                res.DateModification = dateModification;
                nme.SaveChanges();
                logger.Info("[FONTION UPDATE] : note.NAME => ["+note.Name+"]");

                return new NoteDTO(res);
            }
        }
        /// <summary>
        /// <see cref="INoteManagerService.SaveNote(string, string, int, DateTime, DateTime)"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="message"></param>
        /// <param name="utilisateur"></param>
        /// <param name="dateCreation"></param>
        /// <param name="dateModification"></param>
        /// <returns></returns>
        public NoteDTO SaveNote(string name, string message, int utilisateur, DateTime dateCreation, DateTime dateModification)
        {
            if (name == null || message == null || dateCreation == null || dateModification == null)
            {
                throw new ArgumentNullException("CreateNote : title or message or dates failed");
            }
            using (var nme = new NoteManagerEntities())
            {
                var existingNote = from n in nme.Note where n.Name == name && n.UserId == utilisateur select n;
                Note res;
                if (existingNote.Count() > 0)
                {
                    res = existingNote.First();
                    res.Message = message;
                    res.DateModification = dateModification;
                }
                else
                {
                    var id = MaxIdNotes(nme.Note) + 1;
                    res = new Note();
                    res.Id = id;
                    res.Name = name;
                    res.Message = message;
                    res.DateCreation = dateCreation;
                    res.DateModification = dateModification;
                    res.UserId = utilisateur;
                    nme.Note.Add(res);
                }
                //res.User = user.First();
                nme.SaveChanges();

                return new NoteDTO(res);
            }
        }