Exemplo n.º 1
0
        public async Task <ResultDto> RemoveViewer(ShowRoomViewerDto dto)
        {
            var result = new ResultDto();

            try
            {
                var viewData = await _liveShowDB.ShowRoomViewer.AsNoTracking().Where(x => x.UserId == dto.UserId && x.ShowRoomId == dto.ShowRoomId).FirstOrDefaultAsync();

                if (null == viewData)
                {
                    return(result);
                }
                _liveShowDB.ShowRoomViewer.Remove(viewData);
                var flag = _liveShowDB.SaveChanges();
                if (flag > 0)
                {
                    result.ActionResult = true;
                    result.Message      = "Success";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 进入房间
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ResultDto> Add(ShowRoomViewerDto dto)
        {
            var result = new ResultDto();

            dto.CreateTime = DateTime.Now;
            try
            {
                if (await _liveShowDB.ShowRoom.AsNoTracking().Where(x => (x.IsDeleted || (x.Status == ShowRoomStatusEnum.Ban.GetHashCode() || x.Status == ShowRoomStatusEnum.Disable.GetHashCode())) && x.Id == dto.ShowRoomId).AnyAsync())
                {
                    return(result);
                }
                if (await _liveShowDB.ShowRoom.AsNoTracking().Include(x => x.ShowRoomVlewers).Where(x => x.ShowRoomVlewers.Count >= 10000 && !x.ShowRoomVlewers.Where(y => y.UserId == dto.UserId).Any() && x.Id == dto.ShowRoomId).AnyAsync())
                {
                    result.Message = "Over Size";
                    return(result);
                }
                var data = await _liveShowDB.ShowRoomViewer.Where(x => x.UserId == dto.UserId).FirstOrDefaultAsync();

                if (null == data)
                {
                    _liveShowDB.ShowRoomViewer.Add(new ShowRoomViewer()
                    {
                        ShowRoomId = dto.ShowRoomId,
                        UserId     = dto.UserId
                    });
                }
                else if (data.ShowRoomId == dto.ShowRoomId)
                {
                    result.ActionResult = true;
                    result.Message      = "Already in the room";
                }
                else if (data.ShowRoomId != dto.ShowRoomId)
                {
                    _liveShowDB.Remove(data);
                    _liveShowDB.ShowRoomViewer.Add(new ShowRoomViewer()
                    {
                        ShowRoomId = dto.ShowRoomId,
                        UserId     = dto.UserId
                    });
                }
                var flag = _liveShowDB.SaveChanges();
                result.ActionResult = true;
                result.Message      = "Success";
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <ResultDto> AddViewer(ShowRoomViewerDto dto)
        {
            var result = new ResultDto();

            try
            {
                if (await _liveShowDB.ShowRoom.AsNoTracking().Where(x => (x.IsDeleted || (x.Status == ShowRoomStatusEnum.Ban.GetHashCode() || x.Status == ShowRoomStatusEnum.Disable.GetHashCode())) && x.Id == dto.UserId).AnyAsync())
                {
                    return(result);
                }
                if (await _liveShowDB.ShowRoom.AsNoTracking().Include(x => x.ShowRoomVlewers).Where(x => x.ShowRoomVlewers.Count >= 10000 && x.Id == dto.ShowRoomId).AnyAsync())
                {
                    result.Message = "Over Size";
                    return(result);
                }
                var viewerData = await _liveShowDB.ShowRoomViewer.Where(x => x.UserId == dto.UserId).FirstOrDefaultAsync();

                if (null == viewerData)
                {
                    if (await _liveShowDB.ShowRoomViewer.AsNoTracking().Where(x => x.UserId == dto.UserId && x.ShowRoomId == dto.ShowRoomId).AnyAsync())
                    {
                        _liveShowDB.ShowRoomViewer.Add(new ShowRoomViewer()
                        {
                            ShowRoomId = dto.ShowRoomId,
                            UserId     = dto.UserId
                        });
                    }
                }
                else
                {
                    viewerData.ShowRoomId = dto.ShowRoomId;
                    _liveShowDB.ShowRoomViewer.Update(viewerData);
                }
                var flag = _liveShowDB.SaveChanges();
                //if (flag > 0)
                //{
                result.ActionResult = true;
                result.Message      = "Success";
                //}
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(result);
        }
        public async Task AddTest()
        {
            var mockSet     = new Mock <DbSet <ShowRoomViewer> >().SetupList(_sampleList);
            var mockRoomSet = new Mock <DbSet <ShowRoom> >().SetupList(_sampleRoomList);
            var mockContext = new Mock <LiveShowDBContext>();

            mockContext.Setup(x => x.ShowRoomViewer).Returns(mockSet.Object);
            mockContext.Setup(x => x.ShowRoom).Returns(mockRoomSet.Object);
            var mockSvc = new ShowRoomViewerSvc(mockContext.Object);

            var dto = new ShowRoomViewerDto()
            {
                UserId = 2, ShowRoomId = 2
            };
            await mockSvc.Add(dto);

            mockSet.Verify(x => x.Add(It.IsAny <ShowRoomViewer>()), Times.Once());
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
Exemplo n.º 5
0
        public async Task <JsonResult> Remove(ShowRoomViewerDto dto)
        {
            var resultTask = _showRoomViewerSvc.Remove(dto);

            return(Json(await resultTask));
        }