Exemplo n.º 1
0
        public JsonResult AddComment(int roomId, int userId, string text, HttpPostedFileBase file)
        {
            var comment = new ChatCommentEntity
            {
                RoomId = roomId,
                UserId = userId,
                Text   = text,
                Image  = "",
                Date   = DateTime.Now
            };

            var d = _roomsService.AddComment(comment, file);

            return(Json(d, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ChatCommentEntity AddComment(ChatCommentEntity comment, HttpPostedFileBase file)
        {
            using (var db = new groubel_dbEntities1())
            {
                var upload = new IOHandler("~/Uploads/RoomFiles/");

                var name = upload.Save(file);

                var newComm = new ChatComment
                {
                    Attachement = name,
                    Date        = DateTime.Now,
                    RoomId      = comment.RoomId,
                    Text        = comment.Text,
                    UserId      = comment.UserId,
                    Image       = name,
                };

                db.ChatComments.Add(newComm);

                var rm = db.Chats.FirstOrDefault(i => i.Id == comment.RoomId && i.IsRoom == false);
                if (rm != null)
                {
                    rm.IsArchive = false;
                }

                db.SaveChanges();

                comment.Id          = newComm.Id;
                comment.Attachement = name;
                comment.Image       = name;
                comment.Date        = DateTime.Now;
                comment.User        = _userService.GetUserById(comment.UserId, comment.UserId);

                if (db.Chats.FirstOrDefault(i => i.Id == comment.RoomId).IsRoom)
                {
                    _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.CommentedInRoom, comment.RoomId, "", null);
                }
                else
                {
                    _notificationService.AddNotification(comment.UserId, 0, NotificationTypeEnum.SendMessageInChat, comment.RoomId, "", null);
                }

                return(comment);
            }
        }