public ActionResult Attend([FromBody] int gigId) { var errors = new List <string>(); var userId = _managerSecurity.GetUserId(User); if (_context.Attendances.Any(a => a.UserId == userId && a.GigId == gigId)) { errors.Add("The attendance already exists!"); } else { var entity = new Attendance { GigId = gigId, UserId = userId }; _context.Attendances.Add(entity); _context.SaveChanges(); } if (errors.Count == 0) { return(StatusCode(StatusCodes.Status201Created)); } else { return(StatusCode(StatusCodes.Status409Conflict, new { values = errors })); } }
public ActionResult Create([FromBody] ViewModelGig viewModel) { var errors = new List <string>(); if (ModelState.IsValid) { _context.Gigs.Add(new Gig { Venue = viewModel.Venue, DateTime = viewModel.GetDateTime(), GenreId = viewModel.GenreId, ArtistId = _managerSecurity.GetUserId(User) }); _context.SaveChanges(); } else { errors.AddRange(_GetModelStateErrors()); } if (errors.Count == 0) { return(StatusCode(StatusCodes.Status200OK)); } else { return(StatusCode(StatusCodes.Status400BadRequest, new { values = errors })); } }
public ActionResult Follow([FromBody] int followeeId) { var errors = new List <string>(); var followerId = _userManager.GetUserId(User); if (followerId != null) { if (followeeId == int.Parse(followerId)) { errors.Add("The user cannot follow himself!"); } else if (_context.Followings.Any(f => f.FolloweeId == followeeId && f.FollowerId == int.Parse(followerId))) { errors.Add("Following already exist!"); } else { var entity = new Following { FolloweeId = followeeId, FollowerId = int.Parse(followerId) }; _context.Followings.Add(entity); _context.SaveChanges(); } } else { // 401.. errors.Add("Follower does not exist!"); } if (errors.Count == 0) { return(StatusCode(StatusCodes.Status201Created)); } else { return(StatusCode(StatusCodes.Status409Conflict, new { values = errors })); } }