示例#1
0
        public IActionResult Insert(ChannelInsertModel channelInsertModel)
        {
            BaseResponseDto responseDto = null;

            if (channelInsertModel == null)
            {
                return(BadRequest("Sharing info must not be null"));
            }

            try
            {
                responseDto = _channel.Insert(channelInsertModel);
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }

            return(Ok(responseDto.Message));
        }
        public BaseResponseDto Insert(ChannelInsertModel channelInsertModel)
        {
            BaseResponseDto responseDto = null;

            if (channelInsertModel == null)
            {
                responseDto = new BaseResponseDto
                {
                    Status  = 1,
                    Message = "Faulthy channel info"
                };
                return(responseDto);
            }

            Channel existingChannel = null;

            try
            {
                existingChannel = _uow
                                  .GetRepository <Channel>()
                                  .GetAll()
                                  .FirstOrDefault(c =>
                                                  c.TopicId == channelInsertModel.TopicId &&
                                                  c.MentorId == channelInsertModel.MentorId);
            }
            catch (Exception e)
            {
                throw e;
            }

            if (existingChannel != null)
            {
                responseDto = new BaseResponseDto
                {
                    Status  = 2,
                    Message = "Channel already exist"
                };
                return(responseDto);
            }

            try
            {
                Channel newChannel = new Channel
                {
                    ChannelId = Guid.NewGuid(),
                    TopicId   = channelInsertModel.TopicId,
                    MentorId  = channelInsertModel.MentorId,
                    IsDisable = false
                };

                _uow.GetRepository <Channel>().Insert(newChannel);
                _uow.Commit();
            }
            catch (Exception e)
            {
                throw e;
            }

            responseDto = new BaseResponseDto
            {
                Status  = 0,
                Message = "Channel successfully inserted"
            };

            return(responseDto);
        }