Exemplo n.º 1
0
        public IHttpActionResult Attend(AttendanceDto 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());
        }
Exemplo n.º 2
0
        public IHttpActionResult Attend(AttendanceDto attendanceDto)
        {
            var userId     = User.Identity.GetUserId();
            var attendance = new Attendance
            {
                CourseId   = attendanceDto.CourseId,
                AttendeeId = userId
            };

            if (_dbContext.Attendances.Any(a => a.AttendeeId == userId && a.CourseId == attendanceDto.CourseId))
            {
                //_dbContext.Attendances.Remove(attendance);
                _dbContext.Entry(attendance).State = System.Data.Entity.EntityState.Deleted;
                _dbContext.SaveChanges();
                return(Json(new { isFollow = false }));
            }
            _dbContext.Attendances.Add(attendance);
            _dbContext.SaveChanges();
            return(Json(new { isFollow = true }));
        }