Esempio n. 1
0
        public void AddToRoom(string roomName)
        {
            using (var db = new RouteExtremeDbContext())
            {
                var user = db.Users
                    .Include(u => u.ChatRooms)
                    .SingleOrDefault(u => u.UserName == Context.User.Identity.Name);

                var room = db.ChatRooms.FirstOrDefault(x => x.Name == roomName);

                if (room != null)
                {
                    db.Users.Attach(user);
                    room.Users.Add(user);

                }
                else
                {
                    var newRoom = new ChatRoom
                    {
                        Name = roomName,
                        ConnectionId = Context.ConnectionId
                    };

                    newRoom.Users.Add(user);
                    db.ChatRooms.Add(newRoom);
                }

                db.SaveChanges();
                Groups.Add(Context.ConnectionId, roomName);
            }
        }
 public void Update(ChatRoom room)
 {
     this.rooms.Update(room);
     this.rooms.SaveChanges();
 }
 public void Create(ChatRoom room)
 {
     this.rooms.Add(room);
     this.rooms.SaveChanges();
 }
 public void MarkAsDeleted(ChatRoom room)
 {
     this.rooms.MarkAsDeleted(room);
     this.rooms.SaveChanges();
 }
 public ActionResult Destroy([DataSourceRequest]DataSourceRequest request, ChatRoom chatRoom)
 {
     this.ChatRoomService.MarkAsDeleted(chatRoom);
     
     return Json(new[] { chatRoom }.ToDataSourceResult(request, ModelState));
 }