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);
        }
Ejemplo n.º 2
0
 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);
        }