Ejemplo n.º 1
0
        public async Task <IActionResult> AddAnnouncement(AnnouncementForAdd announcementForAdd)
        {
            var announcement = _mapper.Map <Announcement>(announcementForAdd);
            var userId       = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var subcategoy   = await _subcategoryService.GetSubcategoryByName(announcementForAdd.SubcategoryName);

            if (subcategoy == null)
            {
                return(BadRequest("Invalid subcategory"));
            }

            announcement.PostedById  = userId;
            announcement.Subcategory = subcategoy;

            await _announcementService.AddAnnouncement(announcement);

            return(Ok(new { announcementId = announcement.Id }));
        }