Esempio n. 1
0
 public void UpdateValidation(HashtagUpdateDTO hashtagUpdateDTO)
 {
     if (hashtagUpdateDTO.Id <= 0)
     {
         throw new ServiceException(ExceptionMessages.HASHTAG_ID_NOT_AVAILABLE);
     }
     else if (string.IsNullOrEmpty(hashtagUpdateDTO.Name))
     {
         throw new ServiceException(ExceptionMessages.HASHTAG_NAME_CANNOT_BE_BLANK);
     }
 }
Esempio n. 2
0
        public void Update(HashtagUpdateDTO hashtagUpdateDTO)
        {
            var hashtag = _context.Hashtags.FirstOrDefault(x => x.Id == hashtagUpdateDTO.Id);

            if (hashtag == null)
            {
                throw new ServiceException(ExceptionMessages.HASHTAG_NOT_FOUND);
            }
            hashtag.Name = hashtagUpdateDTO.Name;
            _context.Hashtags.Update(hashtag);
            _context.SaveChanges();
        }
 public IActionResult Put([FromBody] HashtagUpdateDTO hashtagUpdateDTO)
 {
     try
     {
         _hashtagService.UpdateValidation(hashtagUpdateDTO);
         _hashtagService.Update(hashtagUpdateDTO);
         return(Ok());
     }
     catch (AuthenticationException)
     {
         return(Forbid());
     }
     catch (ServiceException ex)
     {
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.StackTrace));
     }
 }