public ActionResult Create([FromForm] Announcement announcement)
 {
     if (ModelState.IsValid)
     {
         var claimsIdentity = (ClaimsIdentity)this.User.Identity;
         var claim          = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier);
         var userId         = claim.Value;
         announcement.UserID    = userId;
         announcement.CreatedOn = DateTime.Now;
         _announcementService.AddAnnouncement(announcement);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Пример #2
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 }));
        }
 public async Task <IActionResult> AddAnnouncement(AddAnnouncementDto newAnnouncement)
 {
     return(Ok(await _announcementService.AddAnnouncement(newAnnouncement)));
 }