Exemplo n.º 1
0
        public async Task <ActionResult> DownloadFile(int id, bool download = false)
        {
            var db      = new OllertDbContext();
            var fichier = await db.Fichiers.FirstAsync(f => f.Id == id);

            if (!fichier.ContentType.Contains("image") && !download)
            {
                fichier.Data = System.IO.File.ReadAllBytes(HttpContext.Request.MapPath(HttpContext.Request.ApplicationPath) + "/Content/images/text_enriched.png");
            }

            return(File(fichier.Data, fichier.ContentType));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> UserLastSeen()
        {
            var    db          = new OllertDbContext();
            string userId      = this.User.Identity.GetUserId();
            var    currentUser = await db.Users.FirstAsync(u => u.Id == userId);

            currentUser.LastViewed = DateTime.Now;
            await db.SaveChangesAsync();

            var result = Json(true);

            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return(result);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> AddFileToCard(HttpPostedFileBase file, int cardId)
        {
            Fichier fichier = null;

            if (file.ContentLength != 0)
            {
                byte[] fileData = null;
                using (var binaryReader = new BinaryReader(file.InputStream))
                {
                    fileData = binaryReader.ReadBytes(file.ContentLength);
                }

                var db    = new OllertDbContext();
                var carte = await db.Cartes
                            .Include(c => c.Fichiers)
                            .Include(c => c.Tableau.Salle.Proprietaire)
                            .FirstAsync(c => c.Id == cardId);

                fichier = new Fichier
                {
                    Data        = fileData,
                    Nom         = file.FileName,
                    DateEnvoi   = DateTime.Now,
                    ContentType = file.ContentType
                };
                carte.Fichiers.Add(fichier);

                await db.SaveChangesAsync();

                // Ajoute une notification
                await Ollert.Services.NotificationService.AddNotification <Fichier>(
                    "Fichier Ajouté",
                    "{0} a ajouté un fichier a la carte : 'Demande {1}'".FormatWith(this.User.Identity.Name, carte.NumeroDemande),
                    TypeNotification.AjoutFichier,
                    fichier,
                    fichier.Carte.Tableau.Salle.Id);
            }

            var result = await Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.SerializeObject(fichier));

            return(Content(result, "application/json"));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Salle(int id = -1)
        {
            var currentUserId = this.User.Identity.GetUserId();

            var db    = new OllertDbContext();
            var salle = await db.Salles
                        .Where(s => s.ParticipantsSalle.Count(p => p.Participant.Id == currentUserId) > 0 || s.Proprietaire.Id == currentUserId)
                        .FirstOrDefaultAsync(s => s.Id == id);

            if (salle == null)
            {
                return(RedirectToAction("List"));
            }

            this.ViewBag.Title    = salle.Nom;
            this.ViewBag.SalleId  = salle.Id;
            this.ViewBag.NomSalle = salle.Nom;

            db.Dispose();

            return(View());
        }
Exemplo n.º 5
0
        public static async Task AddNotification <T>(string titre, string message, TypeNotification type, T objetMessage, int salleId) /*where T : IEntity*/
        {
            var hubContext = GlobalHost.ConnectionManager.GetHubContext <OllertHub>();
            var db         = new OllertDbContext();

            var userId      = HttpContext.Current.User.Identity.GetUserId();
            var currentUser = await db.Users.FirstAsync(u => u.Id == userId);

            // les ids de connexion SignalR de l' utilisateur
            var userConnIds = OllertHub.ConnectedUsers.Where(u => u.Key == userId).SelectMany(u => u.Value.ConnectionIds.ToArray()).ToArray();

            // Maj de l' interface des clients connectes
            switch (type)
            {
            case TypeNotification.NouveauMessage: hubContext.Clients.AllExcept(userConnIds).newMessage(objetMessage);
                break;

            case TypeNotification.MouvementCarte: hubContext.Clients.AllExcept(userConnIds).newMove(objetMessage);
                break;

            case TypeNotification.NouvelleCarte: hubContext.Clients.AllExcept(userConnIds).newCard(objetMessage);
                break;

            case TypeNotification.EditionCarte: hubContext.Clients.AllExcept(userConnIds).changeCard(objetMessage);
                break;

            case TypeNotification.AjoutFichier: hubContext.Clients.AllExcept(userConnIds).addFile(objetMessage);
                break;

            case TypeNotification.SuppressionCarte: hubContext.Clients.AllExcept(userConnIds).deleteCard(objetMessage);     // TODO
                break;

            case TypeNotification.SuppressionFichier: hubContext.Clients.AllExcept(userConnIds).deleteFile(objetMessage);
                break;

            case TypeNotification.SuppressionMessage: hubContext.Clients.AllExcept(userConnIds).deleteMessage(objetMessage);     // TODO
                break;

            case TypeNotification.AjoutEtape: hubContext.Clients.AllExcept(userConnIds).addStep(objetMessage);     // TODO
                break;

            case TypeNotification.SuppressionEtape: hubContext.Clients.AllExcept(userConnIds).deleteStep(objetMessage);     // TODO
                break;

            case TypeNotification.ModificationEtape: hubContext.Clients.AllExcept(userConnIds).changeStep(objetMessage);     // TODO
                break;

            default:
                break;
            }

            var notification = new Notification {
                Date     = DateTime.Now,
                Titre    = titre,
                Texte    = message,
                Type     = type,
                Createur = currentUser
            };

            db.Notifications.Add(notification);
            await db.SaveChangesAsync();

            // Notification globale
            hubContext.Clients.AllExcept(userConnIds).newNotification(notification);

            // Recupere les participants de la salle et envoi l'email sans attendre la fin de la tache
            // TODO : reactivate mails

            /*var salle = await db.Salles
             *  .Include(p => p.ParticipantsSalle)
             *  .Include(p => p.ParticipantsSalle.Select(ps => ps.Participant))
             *  .FirstOrDefaultAsync(s => s.Id == salleId);
             * if(salle != null)
             * {
             *  var participants = salle.Participants.ToList();
             *  participants.Add(salle.Proprietaire);
             *
             *  foreach (var user in participants.Where(p => p.Id != userId))
             *  {
             *      if (!string.IsNullOrWhiteSpace(user.Email))
             *      {
             *          var eventMailer = new NotificationMailer();
             *          var mailTask = eventMailer.NewEvent(new MailEventViewModel
             *          {
             *              Titre = titre,
             *              Message = message,
             *              SalleId = salleId
             *          },
             *              currentUser.Email)
             *              .SendAsync();
             *      }
             *  }
             * }*/

            db.Dispose();
        }