Esempio n. 1
0
        //GET api/users/getbyid
        public IHttpActionResult GetById(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            User user;

            user = _userRepo.GetById((int)id);
            if (user == null)
            {
                return(NotFound());
            }
            return(Ok(UsersMapper.MapUserToUserDto(user)));
        }
Esempio n. 2
0
        //POST api/users/login
        public IHttpActionResult Login(UserDto input)
        {
            if (input.UserName == null || input.Password == null)
            {
                return(BadRequest());
            }
            User user;

            user = _userRepo.Single(x => (x.UserName.Equals(input.UserName)) && (x.Password.Equals(input.Password)));
            if (user == null)
            {
                return(Unauthorized());
            }
            return(Ok(UsersMapper.MapUserToUserDto(user)));
        }
        //GET api/events/getevent
        public IHttpActionResult GetEvent(int id)
        {
            Event ev = _eventRepo.Single(x => x.Id == id);

            if (ev == null)
            {
                return(BadRequest("event ne postoji"));
            }
            List <UserDto> participants = UsersMapper.MapUserToUserDto(ev.Participants.ToList(), ev.Sport.Id);

            participants.Add(UsersMapper.MapUserToUserDto(ev.Creator));
            EventParticipantsDto result = EventMapper.MapEventsToEventParticipantsDto(ev, participants);

            return(Ok(result));
        }