Пример #1
0
        public IHttpActionResult Attend(AttendanceDTO dto)
        {
            var userId = User.Identity.GetUserId();

            if (_context.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId))
            {
                return(BadRequest("The attendance already exists."));
            }

            var attendance = new Attendance
            {
                GigId      = dto.GigId,
                AttendeeId = userId
            };

            _context.Attendances.Add(attendance);
            _context.SaveChanges();

            return(Ok());
        }
Пример #2
0
        public IHttpActionResult Attend(AttendanceDTO dto)
        {
            string userId = User.Identity.GetUserId();
            bool   exists = db.Attendances.Any(x => x.AttendeeId == userId && x.GigId == dto.GigId);

            if (!exists)
            {
                Attendance attendance = new Attendance();
                attendance.GigId      = dto.GigId;
                attendance.AttendeeId = userId;

                db.Attendances.Add(attendance);
                db.SaveChanges();
                return(Ok());
            }

            else
            {
                return(BadRequest("You are already attending this event"));
            }
        }
Пример #3
0
        public IHttpActionResult Attend(AttendanceDTO dto) //api will read not read int id
        {
            var UserId = User.Identity.GetUserId();        //GET USERIS

            //CHECK EXSISTS

            if (_context.Attendances.Any(a => a.AttendeeId == UserId && a.GigId == dto.GigId))
            {
                return(BadRequest("The attendance alreday exsist!"));
            }

            var attendance = new Attendance
            {
                GigId      = dto.GigId,
                AttendeeId = User.Identity.GetUserId()
            };

            _context.Attendances.Add(attendance);
            _context.SaveChanges();
            return(OK());
        }