Ejemplo n.º 1
0
        /// <summary>
        /// Creates a New Room
        /// </summary>
        /// <returns>Create View</returns>
        public ActionResult CreateRoom()
        {
            string privacy = Request["privacy"].ToLower();
            string RoomNamePublic = Request["roomnamepublic"];
            string RoomNamePrivate = Request["roomnameprivate"];
            string Password = Request["roompassword"];
            string Genre = Request["genre"];
            string username = User.Identity.Name;
            if (privacy == "1")
            {
                RoomModel room = new RoomModel(RoomNamePublic);
                SongManager.AddRoom(room, User.Identity.Name);
                AccountModel user = SongManager.GetAccountModel(username);
                room = SongManager.GetRoomModel(RoomNamePublic);
                room.Accounts = SongManager.GetRoomAccounts(room.RoomName);
                room.Accounts.Add(user);

                return View("Create", room);
            }
            else
            {
                RoomModel room = new RoomModel(RoomNamePrivate, Password);
                SongManager.AddRoom(room, User.Identity.Name);
                AccountModel user = SongManager.GetAccountModel(username);
                room = SongManager.GetRoomModel(RoomNamePrivate);
                room.Accounts = SongManager.GetRoomAccounts(room.RoomName);
                room.Accounts.Add(user);
                return View("Create", room);
            }
        }
Ejemplo n.º 2
0
 public static Room RoomModelToEntity(RoomModel model)
 {
     Room entity = new Room();
     entity.RoomName = !string.IsNullOrEmpty(model.RoomName) ? model.RoomName : "";
     entity.RoomPassword = !string.IsNullOrEmpty(model.RoomPassword) ? model.RoomPassword : "";
     entity.Privacy = model.Privacy;
     return entity;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds Users to the existing room
        /// </summary>
        /// <param name="room">Room that user is being added to</param>
        /// <param name="account">AccountModel of user being added to room</param>
        public void AddRoomAccount(RoomModel room, AccountModel account)
        {
            if (!SongRepository.GetRoomAccounts(room.RoomId).Any(a => a.Username == account.Username))
            {
                SongRepository.AddRoomAccount(room.RoomId, account.LoginId);

            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a new room to the database
        /// </summary>
        /// <param name="room">RoomModel of room being created</param>
        /// <param name="username">Username of user creating the room</param>
        public void AddRoom(RoomModel room, string username)
        {
            if (SongRepository.IsRoomListEmpty())
            {
                AccountModel account = GetAccountModel(username);
                SongRepository.AddRoom(room, account.LoginId);

            }
            else if (!SongRepository.GetRoomList().Any(a => a.RoomName == room.RoomName) && SongRepository.GetAccountsList().Any(a => a.Username == username))
            {
                AccountModel account = GetAccountModel(username);
                SongRepository.AddRoom(room, account.LoginId);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns an account list of the room to display on the playlist
 /// </summary>
 /// <param name="room">RoomModel of room with accountlist</param>
 /// <returns>IQueryable of AccountModels</returns>
 public IQueryable<AccountModel> GetAccountsList(RoomModel room)
 {
     return _context.Accounts.Where(a => a.Room.Id == room.RoomId)
        .Select(a => new AccountModel
        {
            LoginId = a.LoginId,
            Username = a.Username
        });
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a Room to the database
        /// </summary>
        /// <param name="room">RoomModel being added</param>
        /// <param name="loginId">loginId of user creating room</param>
        public void AddRoom(RoomModel room, int loginId)
        {
            try
            {
                //Convert RoomModel to Entity
                Room entity;
                entity = ModelConversions.RoomModelToEntity(room);

                //Get the host account based on loginId and add its association to the room.
                Account account = GetAccount(loginId);
                entity.Accounts.Add(account);
                _context.Rooms.Add(entity);

                //push to database
                _context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets the account list related to the roomModel
 /// </summary>
 /// <param name="room">RoomModel for room being passed in</param>
 /// <returns>List of AccountModel</returns>
 public List<AccountModel> GetAccountList(RoomModel room)
 {
     return SongRepository.GetAccountsList(room).ToList();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Method for leaving a room. This will remove the user from the room and set the users room information to null
 /// </summary>
 /// <param name="room">Room that user is being deleted from</param>
 /// <param name="username">Username of user that is being deleted from room</param>
 public void DeleteAccount(RoomModel room, string username)
 {
     int roomid = room.RoomId;
     AccountModel account = GetAccountModel(username);
     SongRepository.DeleteAccount(roomid, account.LoginId);
 }