public bool SendDocumentToUser(int fromUserId, int toUserId, int documentId)
        {
            try
            {
                using (DocumentShareEntities db = new DocumentShareEntities())
                {
                    User user = db.Users.Where(o => o.Id == fromUserId).FirstOrDefault();
                    
                    if (user == null)
                        throw new Exception("User was not found");

                    Document doc = db.Documents.Where(o => o.DocumentId == documentId).FirstOrDefault();

                    if (doc == null)
                        throw new Exception("Document was not found");

                    UserDocument userDoc = new UserDocument();
                    userDoc.DocumentId = documentId;
                    userDoc.UserId = toUserId;

                    db.UserDocuments.Add(userDoc);

                    db.SaveChanges();

                    return true;
                }
            }
            catch (Exception e)
            {
                LogError(e);
                return false;
            }
        }
 public Document GetDocumentbyId(int userId, int documentId)
 {
     try
     {
         using (DocumentShareEntities db = new DocumentShareEntities())
         {
             return db.Documents.Where(o => o.DocumentId == documentId).FirstOrDefault();
         }
     }
     catch (Exception e)
     {
         LogError(e);
         return null;
     }
 }
        public List<Document> GetAllDocuments(int userId)
        {
            try
            {
                using (DocumentShareEntities db = new DocumentShareEntities())
                {
                    List<Document> docs;

                    docs = (from doc in db.Documents
                            join udc in db.UserDocuments on doc.DocumentId equals udc.DocumentId
                            where udc.UserId == userId
                            select doc).ToList();

                    return docs;
                }
            }
            catch (Exception e)
            {
                LogError(e);
                return null;
            }
        }
        internal void LogError(Exception e, String notes = "")
        {
            try
            {
                using (DocumentShareEntities db = new DocumentShareEntities())
                {
                    ErrorLog err = new ErrorLog();
                    err.Message = String.Format("{0} {1}", e.Message, e.InnerException == null ? String.Empty : "(" + e.InnerException.Message + ")").Substring(0, 500);
                    err.Notes = notes;

                    db.ErrorLogs.Add(err);
                }
            }
            catch (Exception e)
            {
                //hmmm...
            }
        }