public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; if (_context.Attendances.Any(a => a.GigId == dto.GigId && a.AttendeeId == userId)) { return(BadRequest("Attendance already exists")); } _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); if (db.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId)) { return(BadRequest("The Attendance Already Exist !!")); } var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; db.Attendances.Add(attendance); db.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto gigId) { string userId = User.Identity.GetUserId(); if (_context.Attendances.Any(a => a.AttendeeId == userId && a.GigId == gigId.GigId)) { return(BadRequest("The attendance already exists.")); } var attendance = new Attendance { GigId = gigId.GigId, AttendeeId = userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IActionResult Attend([FromBody] AttendanceDto dto) { var userId = _userManager.GetUserId(User); var exists = _dbContext.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId); if (exists) { return(BadRequest("The attendance already exists.")); } var attendance = new Attendance { AttendeeId = userId, GigId = dto.GigId }; _dbContext.Add(attendance); _dbContext.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var alreadyExists = _context.Attendances.Any(a => a.AttendeeId == _userId && a.GigId == dto.GigId); if (alreadyExists) { return(BadRequest("The attendance already exists.")); } var attendance = new Attendance { GigId = dto.GigId, AttendeeId = _userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); if (_context.Attendances.Any(a => a.AttendeeID == userId && a.GigID == dto.GigId)) { return(BadRequest("Você já está participando deste Gig.")); } var attendance = new Attendance { GigID = dto.GigId, AttendeeID = userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend([FromBody] AttendanceDto dto) { var userId = User.Identity.GetUserId(); if (_context.Attendances.Any(x => x.AttendeeId == userId && x.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()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); var attendanceForGig = _unitOfWork.Attendances.GetAttendancesForGig(dto.GigId, userId); if (attendanceForGig != null) { return(BadRequest("The attendance already exist")); } var attendance = new Attendance { GigId = dto.GigId, AttendeeId = User.Identity.GetUserId() }; _unitOfWork.Attendances.Add(attendance); _unitOfWork.Complete(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); // prevent duplicate var exists = _context.Attends.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId); if (exists) { return(BadRequest("the attendance already exist")); } var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; _context.Attends.Add(attendance); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); if (_context.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId)) { //var gig = _context.Gigs.First(g => g.Id == dto.GigId); var gigs = _context.Gigs .Include(g => g.Artist) .Include(g => g.Genre) .Where(g => g.Id == dto.GigId); var gig = gigs.First(); var schedule = gig.Datetime.ToString("dd MMM yyyy, hh:mm tt"); //try //{ // //var ganre = _context.Genres.First(g => g.Id == gig.GenreId); // //var artist = _context.Users.First(u => u.Id == gig.ArtistId); // //return BadRequest($"Already planned to attend {artist.Name}'s {ganre.Name} at {gig.Venue} on {schedule}"); //} //catch { } //return BadRequest($"Already planned to attend the Gig at {gig.Venue} on {schedule}"); return(BadRequest($"Already planned to attend <b>{gig.Artist.Name}</b>'s <strong><i>{gig.Genre.Name}</i></strong> at {gig.Venue} on <u>{schedule}</u>")); } var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }
//ASP.NET Web API by default does not look for scalar parameter like and //integer in the request body, it expecte it to be in the URL //so, in this case we need to decorate the parameter with [FromBody] attribute public IHttpActionResult Attend(AttendanceDto dto) { var userId = User.Identity.GetUserId(); //Need to check for duplicates before inserting any data if (_context.Attendances.Any(a => a.AttendeeId == userId && a.GigId == dto.GigId)) { return(BadRequest("The attendance already exists")); } //Add new attendance var attendance = new Attendance { GigId = dto.GigId, AttendeeId = userId }; _context.Attendances.Add(attendance); _context.SaveChanges(); return(Ok()); }