public IHttpActionResult Attendance([FromBody] AttendaceDto attendaceDto) { try { string userID = User.Identity.GetUserId(); var gig = _context.Gigs.FirstOrDefault(c => c.ID == attendaceDto.gigId); if (gig == null) { return(Content(System.Net.HttpStatusCode.NotFound, $"The Gig with id {attendaceDto.gigId} is not found.")); } var exist = _context.Attendances. FirstOrDefault(c => c.GigId == attendaceDto.gigId && c.AttendeeId == userID); if (exist != null) { _context.Attendances.Remove(exist); _context.SaveChanges(); } else { var attendace = new Attendance() { AttendeeId = userID, GigId = attendaceDto.gigId }; _context.Attendances.Add(attendace); _context.SaveChanges(); } } catch (System.Exception e) { return(StatusCode(System.Net.HttpStatusCode.InternalServerError)); } return(Ok("Added Successfully.")); }
public IHttpActionResult Attend(AttendaceDto dto) { var userId = User.Identity.GetUserId(); // that mean if i click Going by the same username and the gig and want to click again will be error if (_context.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId)) { return(BadRequest("The Attendance Already exists")); } var attendances = new Attendance { GigId = dto.GigId, AttendeeId = userId }; _context.Attendances.Add(attendances); _context.SaveChanges(); return(Ok()); }