Exemple #1
0
        public async Task <Annonce> AddAsync(Annonce annonce)
        {
            context.Add(annonce);
            await context.SaveChangesAsync();

            return(annonce);
        }
Exemple #2
0
        public async Task <IActionResult> PostAnnonce([FromBody] Annonce annonce)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userId = HttpContext.User.Claims.First().Value;

            annonce.UserId = userId;
            _context.Annonces.Add(annonce);
            await _context.SaveChangesAsync();

            return(Ok(annonce));
        }