public async Task <IActionResult> PostPublication([FromBody] Publication publication)
        {
            ApplicationUser applicationUserCur = await GetCurrentUserAsync();

            if (applicationUserCur.Status == "admin" || applicationUserCur.Status == "seller")
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (publication.ApplicationUserId != null)
                {
                    ApplicationUsersController applicationUsers = new ApplicationUsersController(getUMgr(), _context);
                    var applicationUser = await applicationUsers.GetUserToPulication(publication.ApplicationUserId);

                    publication.ApplicationUser = applicationUser;
                }
                publication.ApplicationUser = applicationUserCur;

                _context.Publication.Add(publication);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetPublication", new { id = publication.Id }, publication));
            }
            else
            {
                return(BadRequest("Pas admin ou client"));
            }
        }
Exemple #2
0
        public async Task <IActionResult> PostResponse([FromBody] Response response)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApplicationUser applicationUserCur = await GetCurrentUserAsync();

            if (response.ApplicationUserId != null && response.PublicationId != 0)
            {
                ApplicationUsersController applicationUsers       = new ApplicationUsersController(getUMgr(), _context);
                PublicationsController     publicationsController = new PublicationsController(getUMgr(), _context);
                var applicationUser = await applicationUsers.GetUserToPulication(response.ApplicationUserId);

                var publication = await publicationsController.GetPublicationToResponse(response.PublicationId);

                response.ApplicationUser = applicationUser;
                response.Publication     = publication;
            }
            else
            {
                response.ApplicationUserId = applicationUserCur.Id;
                response.ApplicationUser   = applicationUserCur;
            }


            _context.Response.Add(response);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetResponse", new { id = response.Id }, response));
        }