Esempio n. 1
0
        public async Task UpdateDrafted_Should_Return_Ok()
        {
            // Arrange
            var lotteryViewModel = new EditDraftedLotteryViewModel
            {
                Id    = 31,
                Title = "Hello"
            };

            var lotteryDto = new LotteryDto
            {
                Id    = 31,
                Title = "Hello"
            };

            _mapper.Map <EditDraftedLotteryViewModel, LotteryDto>(lotteryViewModel)
            .Returns(lotteryDto);

            // Act
            var response = await _lotteryController.UpdateDrafted(lotteryViewModel);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <OkResult>(response);
            await _lotteryService.Received(1).EditDraftedLotteryAsync(lotteryDto);
        }
Esempio n. 2
0
        public async Task UpdateDrafted_Should_Return_Bad_Request()
        {
            // Arrange
            var lotteryViewModel = new EditDraftedLotteryViewModel
            {
                Id    = 31,
                Title = "Hello"
            };

            var lotteryDto = new LotteryDto
            {
                Id    = 31,
                Title = "Hello"
            };

            _mapper.Map <EditDraftedLotteryViewModel, LotteryDto>(lotteryViewModel)
            .Returns(lotteryDto);

            _lotteryService.When(x => x.EditDraftedLotteryAsync(lotteryDto))
            .Do(_ => throw new LotteryException("Exception"));

            // Act
            var response = await _lotteryController.UpdateDrafted(lotteryViewModel);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(response);
            await _lotteryService.Received(1).EditDraftedLotteryAsync(lotteryDto);
        }
Esempio n. 3
0
        public async Task <LotteryDto> CreateLotteryAsync(LotteryDto newLotteryDto)
        {
            if (newLotteryDto.EndDate < DateTime.UtcNow)
            {
                throw new LotteryException("Lottery can't start in the past.");
            }

            if (newLotteryDto.EntryFee < 1)
            {
                throw new LotteryException("Invalid entry fee.");
            }

            if (newLotteryDto.Status != (int)LotteryStatus.Started &&
                newLotteryDto.Status != (int)LotteryStatus.Drafted)
            {
                throw new LotteryException("Invalid status of created lottery.");
            }

            var newLottery = MapNewLottery(newLotteryDto);

            _lotteriesDbSet.Add(newLottery);

            await _uow.SaveChangesAsync(newLotteryDto.UserId);

            newLotteryDto.Id = newLottery.Id;

            return(newLotteryDto);
        }
Esempio n. 4
0
        public LotteryDto GetLottery(Guid uid, int type)
        {
            using (var db = base.NewDB())
            {
                var bus = new IntegralBus(db);

                var dblottery = db.Lotterys.Single(t => t.IsValid == true && t.Type == type);

                var dbuser = db.Users.Single(t => t.AuthID == uid);

                var dbul = bus.GetUserLottery(dbuser, dblottery);

                db.SaveChanges();

                var res = new LotteryDto
                {
                    id         = dbul.LotteryID,
                    begintime  = DateTime.Now.Date,
                    endtime    = DateTime.Now.Date.AddDays(1).AddSeconds(-1),
                    costpoints = dblottery.CostPoints,
                    chance     = dbul.Chance,
                    isvalid    = dbul.IsValid,
                    prizes     = GetPrizeDtos(dblottery)
                };
                return(res);
            }
        }
Esempio n. 5
0
 private static void UpdateDraftedLottery(Lottery lottery, LotteryDto draftedLotteryDto)
 {
     lottery.EntryFee    = draftedLotteryDto.EntryFee;
     lottery.EndDate     = draftedLotteryDto.EndDate;
     lottery.Description = draftedLotteryDto.Description;
     lottery.Status      = draftedLotteryDto.Status;
     lottery.Title       = draftedLotteryDto.Title;
     lottery.Images      = draftedLotteryDto.Images;
 }
Esempio n. 6
0
        private Lottery MapNewLottery(LotteryDto newLotteryDto)
        {
            var newLottery = _mapper.Map <LotteryDto, Lottery>(newLotteryDto);

            newLottery.CreatedBy      = newLotteryDto.UserId;
            newLottery.Modified       = DateTime.UtcNow;
            newLottery.ModifiedBy     = newLotteryDto.UserId;
            newLottery.IsRefundFailed = false;

            return(newLottery);
        }
Esempio n. 7
0
        public async Task EditDraftedLotteryAsync(LotteryDto lotteryDto)
        {
            var lottery = await _lotteriesDbSet.FindAsync(lotteryDto.Id);

            if (lottery != null && lottery.Status != (int)LotteryStatus.Drafted)
            {
                throw new LotteryException("Editing is forbidden for not drafted lottery.");
            }

            UpdateDraftedLottery(lottery, lotteryDto);

            await _uow.SaveChangesAsync(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Transform the Lottery into reusable data
        /// </summary>
        /// <param name="lotteryDto"></param>
        private void CreateLottery(LotteryDto lotteryDto)
        {
            // First we need to create the Drawings
            var drawings = TransformDrawings(lotteryDto.Drawings);

            // Create the Lottery
            var lottery = new Lottery()
            {
                Name = lotteryDto.Name, HighestNumber = lotteryDto.HighestNumber, Drawings = drawings
            };

            // Run the statistics
            lottery.GenerateLotteryNumberStatistics();
            lottery.GenerateBonusBallStatistics();
            lottery.GeneratePatternLevelStatistics();

            // Then We need to populate the Lottery
            this.Lotteries.Add(lottery);
        }
Esempio n. 9
0
        public LotteryDto GetLottery1(Guid uid, int type)
        {
            using (var db = base.NewDB())
            {
                var list = new List <PrizeDto> {
                    new PrizeDto {
                        id = 1, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/1.jpg", name = "奖品1"
                    },
                    new PrizeDto {
                        id = 2, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/2.jpg", name = "奖品2"
                    },
                    new PrizeDto {
                        id = 3, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/3.jpg", name = "奖品3"
                    },
                    new PrizeDto {
                        id = 4, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/4.jpg", name = "奖品4"
                    },
                    new PrizeDto {
                        id = 5, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/5.jpg", name = "奖品5"
                    },
                    new PrizeDto {
                        id = 6, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/6.jpg", name = "奖品6"
                    },
                    new PrizeDto {
                        id = 7, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/7.jpg", name = "奖品7"
                    },
                    new PrizeDto {
                        id = 8, imgurl = "https://www.hexieyinan.com/SxcWebApi/Images/Prize/8.jpg", name = "奖品8"
                    },
                };

                var res = new LotteryDto
                {
                    id        = 1,
                    begintime = DateTime.Now.Date,
                    endtime   = DateTime.Now.Date.AddDays(1).AddSeconds(-1),
                    chance    = 3,
                    isvalid   = true,
                    prizes    = list.OrderBy(t => Guid.NewGuid()).ToList()
                };
                return(res);
            }
        }
Esempio n. 10
0
 public IActionResult CreateLottery([FromBody] LotteryDto lotteryDto)
 {
     try
     {
         var LotteryInfo = new Lottery()
         {
             Name        = lotteryDto.Name,
             Probability = lotteryDto.Probability,
             CreatDate   = DateTime.Now,
             SysUserId   = lotteryDto.SysUserId
         };
         _context.Lotterys.Add(LotteryInfo);
         _context.SaveChanges();
         return(Ok("新增成功"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Esempio n. 11
0
 public IActionResult EditLottery([FromBody] LotteryDto lotteryDto)
 {
     try
     {
         var lotteryinfo = _context.Lotterys.Where(x => x.Id == lotteryDto.Id).FirstOrDefault();
         if (lotteryinfo == null)
         {
             return(BadRequest("无该奖品"));
         }
         lotteryinfo.Name        = lotteryDto.Name;
         lotteryinfo.Probability = lotteryDto.Probability;
         lotteryinfo.EditDate    = DateTime.Now;
         _context.SaveChanges();
         return(Ok("修改成功"));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
        public int Create(LotteryDto lotteryDto)
        {
            var lottery = new Lottery
            {
                Name = lotteryDto.Name,
                Date = lotteryDto.Date
            };

            this._context.Lotteries.Add(lottery);

            this._context.AddRange(lotteryDto.CoworkerIds.Select(x => new LotteryCoworker
            {
                Lottery    = lottery,
                CoworkerId = x
            }));

            this._context.SaveChanges();

            return(lottery.Id);
        }
Esempio n. 13
0
        public async Task CreateLottery_Should_Return_Bad_Request()
        {
            // Arrange
            var lotteryViewModel = new CreateLotteryViewModel
            {
                Title = "test"
            };

            var lotteryDto = new LotteryDto
            {
                Title = "test"
            };

            _mapper.Map <CreateLotteryViewModel, LotteryDto>(lotteryViewModel).Returns(lotteryDto);
            _lotteryService.CreateLotteryAsync(lotteryDto).Throws(new LotteryException("Exception"));

            // Act
            var response = await _lotteryController.CreateLottery(lotteryViewModel);

            // Assert
            Assert.IsInstanceOf <BadRequestErrorMessageResult>(response);
            await _lotteryService.Received(1).CreateLotteryAsync(lotteryDto);
        }
Esempio n. 14
0
        public async Task CreateLottery_Should_Return_Ok()
        {
            // Arrange
            var lotteryViewModel = new CreateLotteryViewModel
            {
                Title = "test"
            };

            var lotteryDto = new LotteryDto
            {
                Title = "test"
            };

            _mapper.Map <CreateLotteryViewModel, LotteryDto>(lotteryViewModel).Returns(lotteryDto);

            // Act
            var response = await _lotteryController.CreateLottery(lotteryViewModel);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <OkResult>(response);
            await _lotteryService.Received(1).CreateLotteryAsync(lotteryDto);
        }
Esempio n. 15
0
        public async Task CreateLottery_Should_Return_Invalid_Model_State()
        {
            // Arrange
            var lotteryViewModel = new CreateLotteryViewModel
            {
                Title = "test"
            };

            var lotteryDto = new LotteryDto
            {
                Title = "test"
            };

            _mapper.Map <CreateLotteryViewModel, LotteryDto>(lotteryViewModel).Returns(lotteryDto);

            // Act
            _lotteryController.ModelState.AddModelError("model", "error");

            var response = await _lotteryController.CreateLottery(lotteryViewModel);

            // Assert
            Assert.IsInstanceOf <InvalidModelStateResult>(response);
            await _lotteryService.DidNotReceive().CreateLotteryAsync(lotteryDto);
        }
 public ActionResult <int> CreateLottery([FromBody] LotteryDto dto)
 {
     return(this._lotteryService.Create(dto));
 }
Esempio n. 17
0
        public LotterySystemViewModel(IDispatcherService dispatcherService, string functionTag,
                                      IDialogService dialogService, ScoreInfoService scoreInfoService, LotteryService lotteryService) : base(dispatcherService, functionTag)
        {
            _dialogService    = dialogService;
            _scoreInfoService = scoreInfoService;
            _lotteryService   = lotteryService;

            Timer1 = new Timer()
            {
                AutoReset = true, Interval = LotteryInterval * 1000
            };
            Timer1.Elapsed += OnStartLottery;

            _currentViewModelObserver = new PropertyObserver <LotterySystemViewModel>(this);
            _currentViewModelObserver.RegisterHandler(currentViewModel => currentViewModel.LotteryInterval,
                                                      (vm) =>
            {
                if (LotteryInterval > 0)
                {
                    Timer1.Interval = LotteryInterval * 1000;
                    Timer1.Enabled  = true;
                }
            });

            DataGridItemChanged = new RelayCommand <DataGridItemChangedEventArgs>(OnDataGridItemChanged);

            RefreshList = new RelayCommand(PrivateRefreshList);

            RemoveItem = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除选中数据吗?"))
                {
                    _ = _lotteryService.RemoveAsync(SelectedItem);
                    LotteryItems.Remove(SelectedItem);
                }
            }, () => { return(SelectedItem != null); });

            RemoveAll = new RelayCommand(() =>
            {
                if (_dialogService.ShowOKCancel("确定删除所有数据吗?"))
                {
                    _            = _lotteryService.RemoveAllAsync();
                    LotteryItems = null;
                }
            }, () => { return(LotteryItems != null); });

            AddData = new RelayCommand(() =>
            {
                var dto = new LotteryDto()
                {
                    LotteryName = LotteryName,
                    Content     = Content,
                    Amount      = Amount,
                    Quality     = Quality,
                    LotteryType = LotteryType
                };
                _ = _lotteryService.AddAsync(dto);
                LotteryItems.Add(dto);
            });

            AddAvailableVariables();

            PrivateRefreshList();
        }