예제 #1
0
        public IHttpActionResult Attend(AttendancesDTO attendanceDto)
        {
            var userId = User.Identity.GetUserId();

            if (_dbContext.Attendances.Any(a => a.AttendeeId == userId && a.CourseId == attendanceDto.CourseID))
            {
                return(BadRequest("The Attendance already exists!"));
            }

            var attendance = new Attendance
            {
                CourseId   = attendanceDto.CourseID,
                AttendeeId = userId
            };

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

            return(Ok());
        }
예제 #2
0
        public IHttpActionResult Attend(AttendancesDTO dto)
        {
            var userId     = User.Identity.GetUserId();
            var duplicated = _unitOfWork.Attendances.GetAttendance(dto.GigId, userId) != null;

            if (duplicated)
            {
                return(BadRequest("The attendance already exists."));
            }

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

            _unitOfWork.Attendances.Add(attendace);
            _unitOfWork.Complete();

            return(Ok());
        }