Exemple #1
0
        public ActionResult <IEnumerable <SongRead> > GetAllSongs()
        {
            Request.Headers.TryGetValue("email", out var emailValue);
            Request.Headers.TryGetValue("UserName", out var userID);

            if (_repository.GetUserById(userID) == null)
            {
                if (userID != "")
                {
                    var user = new UserCreate();
                    user.name  = userID;
                    user.email = emailValue;
                    var userModel = _mapper.Map <UserData>(user);
                    _repository.CreateUser(userModel);
                    _repository.SaveChanges();
                }
                else
                {
                    return(Unauthorized("Invalid user"));
                }
            }

            var songItems = _repository.GetAllSongs();

            return(Ok(_mapper.Map <IEnumerable <SongRead> >(songItems)));
        }
Exemple #2
0
        public ActionResult <UserRead> GetUserById(string id)
        {
            var userItem = _repository.GetUserById(id);

            if (userItem != null)
            {
                return(Ok(_mapper.Map <UserRead>(userItem)));
            }
            else
            {
                return(NotFound(null));
            }
        }
Exemple #3
0
        public ActionResult <UserRead> GetUserById(string id)
        {
            var userItem = _repository.GetUserById(id);

            if (userItem != null)
            {
                return(Ok(true));
            }
            else
            {
                return(NotFound(false));
            }
        }