예제 #1
0
        public async Task <IActionResult> PostCommentaireJob([FromBody] CommentaireJob commentaireJob)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            //  commentaireJob.JobId = 1;


            _context.CommentaireJob.Add(commentaireJob);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CommentaireJobExists(commentaireJob.CommentaireId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCommentaireJob", new { id = commentaireJob.CommentaireId }, commentaireJob));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("CommentaireId,AddDate,Description,IdUser,JobId")] CommentaireJob commentaireJob)
        {
            if (id != commentaireJob.CommentaireId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(commentaireJob);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentaireJobExists(commentaireJob.CommentaireId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["JobId"]  = new SelectList(_context.Jobs, "JobId", "JobId", commentaireJob.JobId);
            ViewData["IdUser"] = new SelectList(_context.AppUSers, "Id", "Id", commentaireJob.IdUser);
            return(View(commentaireJob));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("CommentaireId,AddDate,Description,IdUser,JobId")] CommentaireJob commentaireJob)
        {
            if (ModelState.IsValid)
            {
                _context.Add(commentaireJob);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["JobId"]  = new SelectList(_context.Jobs, "JobId", "JobId", commentaireJob.JobId);
            ViewData["IdUser"] = new SelectList(_context.AppUSers, "Id", "Id", commentaireJob.IdUser);
            return(View(commentaireJob));
        }
예제 #4
0
        public async Task <IActionResult> GetCommentaireJob([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CommentaireJob commentaireJob = await _context.CommentaireJob.SingleOrDefaultAsync(m => m.CommentaireId == id);

            if (commentaireJob == null)
            {
                return(NotFound());
            }

            return(Ok(commentaireJob));
        }
예제 #5
0
        public IActionResult OwnCommentaireJob([FromRoute] int id, [FromRoute]  string token)
        {
            if (_context.AppUSers.FirstOrDefault() == null || _context.CommentaireJob.FirstOrDefault() == null)
            {
                return(Ok(true));
            }
            CommentaireJob j = new CommentaireJob();

            j = _context.CommentaireJob.FirstOrDefault(i => i.CommentaireId == id);
            ApplicationUser au = new ApplicationUser();

            au = _context.AppUSers.FirstOrDefault(l => l.Token == token);

            if (j.IdUser == au.Id)
            {
                return(Ok(true));
            }

            return(Ok(false));
        }
예제 #6
0
        public async Task <IActionResult> PutCommentaireJob([FromRoute] int id, [FromBody] CommentaireJob commentaireJob)
        {
            CommentaireJob j = _context.CommentaireJob.FirstOrDefault(t => t.CommentaireId == commentaireJob.CommentaireId);

            j.Description = commentaireJob.Description;


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != commentaireJob.CommentaireId)
            {
                return(BadRequest());
            }

            _context.Entry(j).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentaireJobExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }