コード例 #1
0
        public void DeleteReply(Guid replyId)
        {
            ReplyDE reply = _context.tbl_db_reply.Where(x => x.ReplyId == replyId).FirstOrDefault();

            if (reply == null)
            {
                throw new AppException("ReplyId does not exist");
            }

            _context.tbl_db_reply.Remove(reply);
            _context.SaveChanges();
        }
コード例 #2
0
        public void UpdateReply(ReplyDto replyDto)
        {
            ReplyDE reply = _context.tbl_db_reply.Where(x => x.ReplyId == replyDto.ReplyId).FirstOrDefault();

            if (reply == null)
            {
                throw new AppException("ReplyId does not exist");
            }

            if (!string.IsNullOrEmpty(replyDto.Description))
            {
                reply.Description = replyDto.Description;
            }

            reply.isEdited = true;

            _context.tbl_db_reply.Update(reply);
        }
コード例 #3
0
        public ReplyDE CreateReply(ReplyDto replyDto)
        {
            if (!PostExists(replyDto.PostId))
            {
                throw new AppException("PostId " + replyDto.PostId + " does not exist");
            }

            if (!_userRepository.UserExists(replyDto.CreatedBy))
            {
                throw new AppException("UserId " + replyDto.CreatedBy + " does not exist");
            }

            ReplyDE reply = _mapper.Map <ReplyDE>(replyDto);

            reply.ReplyId   = new Guid();
            reply.CreatedOn = DateTime.Now;
            reply.isEdited  = false;

            _context.tbl_db_reply.Add(reply);
            _context.SaveChanges();

            return(reply);
        }