Beispiel #1
0
        public void UpdateCode(CodeUpdateDTO codeUpdateDTO)
        {
            var currentUser = _userService.GetLoggedInUser();

            if (codeUpdateDTO.Id <= 0)
            {
                throw new ServiceException(ExceptionMessages.CODEID_NOT_AVAILABLE);
            }

            var findedCode = _context.Codes.FirstOrDefault(x => x.Id == codeUpdateDTO.Id);

            if (findedCode == null)
            {
                throw new ServiceException(ExceptionMessages.CODE_NOT_FOUND);
            }

            findedCode.Title       = codeUpdateDTO.CodeDTO.Title;
            findedCode.Description = codeUpdateDTO.CodeDTO.Description;
            findedCode.Body        = codeUpdateDTO.CodeDTO.Code;
            findedCode.Hashtags    = codeUpdateDTO.CodeDTO.Hashtags;
            findedCode.LookupId    = codeUpdateDTO.CodeDTO.LookupId;
            findedCode.UpdatedBy   = currentUser.Id;
            findedCode.UpdatedDate = DateTime.Now;

            _context.Codes.Update(findedCode);
            _context.SaveChanges();
        }
        public IActionResult UpdateCode([FromBody] CodeUpdateDTO codeUpdateDTO)
        {
            try
            {
                _codeService.UpdateCode(codeUpdateDTO);
                return(Ok());
            }
            catch (AuthenticationException)
            {
                return(Forbid());
            }
            catch (ServiceException ex)
            {
                return(BadRequest(ex.Message));
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.StackTrace));
            }
        }