public async Task <bool> DeleteAsync(Guid announcementId, Guid loggedInUserId)
        {
            try
            {
                //get list of announcements for travel plan
                var announcementToDelete = await _announcementRepository.GetAsync(announcementId);

                if (announcementToDelete == null)
                {
                    return(true);
                }

                if (announcementToDelete.CreatedById != loggedInUserId)
                {
                    throw new InsufficientRightsException("User doesn't have rights to delete");
                }

                var isSuccessful = await _announcementRepository.DeleteAsync(announcementToDelete);

                return(isSuccessful);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Delete([FromQuery] Guid announcementId)
        {
            try
            {
                var userId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;

                var isSuccessful = await _announcementRepo.DeleteAsync(announcementId, new Guid(userId));

                if (isSuccessful)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception)
            {
                throw;
            }
        }