コード例 #1
0
        public Ticket AddTicket(CreateTicketReq model)
        {
            Ticket ticket = new Ticket();

            //Take the user
            var user = _context.Users
                       .Where(u => u.Id == model.UserId)
                       .SingleOrDefault();

            //Check if user is admin or does not exist
            if (user == null || user.IsAdmin == true)
            {
                return(null);
            }

            //Set ticket data
            ticket.Id             = 0;
            ticket.LastActionDate = DateTime.Now;
            ticket.OriginDate     = DateTime.Now;
            ticket.Title          = model.Title;
            ticket.User           = user;
            ticket.Status         = "requested";

            //Add ticket
            _context.Tickets.Add(ticket);
            _context.SaveChanges();
            if (ticket.Id == 0)
            {
                return(null);
            }

            //Set first ticket message data
            TicketMessage msg = new TicketMessage {
                Id      = 0,
                Date    = DateTime.Now,
                Content = model.Content,
                User    = user,
                Ticket  = ticket
            };

            //Add first ticket message
            _context.TicketMessages.Add(msg);
            _context.SaveChanges();

            if (msg.Id == 0)
            {
                return(null);
            }

            return(ticket);
        }
コード例 #2
0
        public SlotMachineSpinRes Spin(SlotMachineSpinReq model)
        {
            List <SlotSymbol> symbolsList = new List <SlotSymbol>();

            var user = _context.Users
                       .Where(u => u.Id == model.UserId)
                       .SingleOrDefault();

            //Check if user exists and have enough balance for the spin
            if (user.Balance < model.Bet)
            {
                return(null);
            }

            //Remove the bet from user's balance
            user.Balance -= model.Bet;
            _context.SaveChanges();

            //Fill list with random symbols based on certain odds
            for (var i = 0; i < 9; i++)
            {
                symbolsList.Add(getSymbolFromRandomNumber());
            }

            //Calculate reward(winning) from the spin
            var reward = calculateReward(symbolsList, model.Bet);

            //DB object to insert in 'SlotMachineSpins'
            var dbSpinData = new SlotMachineSpin {
                Id     = 0,
                Time   = DateTime.Now,
                User   = user,
                Game   = model.Game,
                Bet    = model.Bet,
                Reward = reward
            };

            //Insert the object
            _context.SlotMachineSpins.Add(dbSpinData);
            _context.SaveChanges();

            //Add reward from the spin to user's balance
            user.Balance += reward;
            _context.SaveChanges();

            //Return slot symbols to display in FE and the reward(winning)
            return(new SlotMachineSpinRes {
                SymbolsList = symbolsList,
                Reward = reward
            });
        }
コード例 #3
0
ファイル: UserService.cs プロジェクト: toniyanchev/CastleBet
        public User Login(AuthenticateRequest model)
        {
            var user = _context.Users
                       .SingleOrDefault(x => x.Username == model.Username && x.Password == model.Password);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            var rndNumber = new Random().Next(100000, 999999);

            user.LastCode = rndNumber;

            _context.SaveChanges();

            sendVerificationMail(rndNumber, user.Email);

            return(new User {
                Username = model.Username
            });
        }