internal bool hasRelationship(DTOCarFavorite fav) { string sql = "SELECT * FROM carfavorites WHERE carId = @CarId AND user = @User"; var found = _db.QueryFirstOrDefault <DTOCarFavorite>(sql, fav); return(found != null); }
internal DTOCarFavorite Create(DTOCarFavorite fav) { if (_repo.hasRelationship(fav)) { throw new Exception("you already have that fav"); } return(_repo.Create(fav)); }
public ActionResult <DTOCarFavorite> Create([FromBody] DTOCarFavorite fav) { try { fav.User = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; return(Ok(_cfs.Create(fav))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
internal DTOCarFavorite Create(DTOCarFavorite fav) { string sql = @" INSERT INTO carfavorites (user, carid) VALUES (@User, @CarId); SELECT LAST_INSERT_ID(); "; fav.Id = _db.ExecuteScalar <int>(sql, fav); return(fav); }