示例#1
0
        public async Task <IResponse> AddPoints([FromBody] AddPointsModel addPointsModel)
        {
            AddPointsResponse addPointsResponse = new AddPointsResponse();
            PointsModel       points            = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == addPointsModel.UserId);

            Account account = await _userManager.FindByIdAsync(addPointsModel.UserId);

            if (account == null)
            {
                List <string> errors = new List <string>();
                errors.Add("User does not exist.");
                addPointsResponse.Errors = errors;
            }
            else
            {
                if (points == null)
                {
                    _context.Points.Add(new PointsModel {
                        Account = account, Value = 0
                    });
                    await _context.SaveChangesAsync();

                    points = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == addPointsModel.UserId);
                }

                var result = await _pointManager.AddToUserAsync(account, addPointsModel.Value);

                double test = result.pointTransaction.Amount;
                addPointsResponse.Succeeded = result.succeeded;
            }


            return(addPointsResponse);
        }
示例#2
0
        public async Task <(bool succeeded, PointTransactionModel pointTransaction)> RemoveFromUserAsync(Account account,
                                                                                                         double pointValue)
        {
            if (pointValue > 0.0)
            {
                PointsModel points = await _context.Points.SingleOrDefaultAsync(x => x.Account == account);

                if (points != null)
                {
                    if (points.Value != 0.0 || points.Value - pointValue >= 0.0)
                    {
                        PointTransactionModel pointTransactionModel = new PointTransactionModel();
                        pointTransactionModel.Account        = account;
                        pointTransactionModel.PreviousAmount = points.Value;
                        pointTransactionModel.NewAmount      = points.Value - pointValue;
                        pointTransactionModel.DateTime       = DateTime.Now;

                        _context.PointTransactionLog.Add(pointTransactionModel);

                        points.Value = points.Value - pointValue;
                        _context.Points.Update(points);

                        await _context.SaveChangesAsync();

                        return(true, pointTransactionModel);
                    }
                }
            }
            return(false, null);
        }
示例#3
0
        public async Task <IResponse> BuyPoints([FromBody] BuyPointsModel buyPointsModel)
        {
            AddPointsResponse addPointsResponse = new AddPointsResponse();
            PointsModel       points            = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == buyPointsModel.UserId);

            Account account = await _userManager.FindByIdAsync(buyPointsModel.UserId);

            if (account == null)
            {
                List <string> errors = new List <string>();
                errors.Add("User does not exist.");
                addPointsResponse.Errors = errors;
            }
            else
            {
                if (points == null)
                {
                    _context.Points.Add(new PointsModel {
                        Account = account, Value = 0
                    });
                    await _context.SaveChangesAsync();

                    points = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == buyPointsModel.UserId);
                }

                var result = await _pointManager.PurchasePoints(account, buyPointsModel.Value, buyPointsModel.Price);

                addPointsResponse.Succeeded = result;
            }
            return(addPointsResponse);
        }
示例#4
0
        public ActionResult ManagePoints(PointsModel m)
        {
            SAE_DB _Context = new SAE_DB();

            //var data = from PLEDGE select *;

            return(View());
        }
 private void Construct(DiamondModel diamondModel, Vector2 modelPosition, PointsModel pointsModel, QuadTools quadTools)
 {
     _diamondModel = diamondModel;
     _diamondModel.Position.Value = modelPosition;
     _pointsModel = pointsModel;
     _quadTools   = quadTools;
     SetModel(_diamondModel);
 }
示例#6
0
        public async Task <IResponse> RemovePoints([FromBody] AddPointsModel addPointsModel)
        {
            AddPointsResponse addPointsResponse = new AddPointsResponse();
            PointsModel       points            = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == addPointsModel.UserId);

            Account account = await _userManager.FindByIdAsync(addPointsModel.UserId);

            List <string> errors = new List <string>();

            if (account == null)
            {
                errors.Add("User does not exist.");
                addPointsResponse.Errors = errors;
            }
            else
            {
                if (points == null)
                {
                    _context.Points.Add(new PointsModel {
                        Account = account, Value = 0
                    });
                    await _context.SaveChangesAsync();

                    points = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == addPointsModel.UserId);
                }

                if (points.Value >= addPointsModel.Value && !points.Value.Equals(0.0))
                {
                    var result = await _pointManager.RemoveFromUserAsync(account, addPointsModel.Value);

                    double test = result.pointTransaction.Amount;
                    if (result.succeeded)
                    {
                        addPointsResponse.Succeeded = true;
                    }
                    else
                    {
                        errors.Add("Action failed.");
                    }
                }
                else
                {
                    errors.Add("User doesn't have enough points");
                }
            }
            if (errors.Count > 0)
            {
                addPointsResponse.Errors = errors;
            }


            return(addPointsResponse);
        }
示例#7
0
        /// <summary>
        /// Metoda aktualizująca wykresy
        /// </summary>

        private void UpdateModels()
        {
            var category = _iterations.Count;

            var d = CalculateModels(GetStateByIteration(category));


            _iterations.Add(new Tuple <int, String>(category, ""));

            foreach (var s in GenerateColumns(category, d[0]))
            {
                var columnSeries = CountModel.Series[0] as ColumnSeries;
                if (columnSeries != null)
                {
                    columnSeries.Items.Add(s);
                }
            }
            if (category > 0)
            {
                foreach (var s in GenerateColumns(category - 1, d[1]))
                {
                    var columnSeries = PointsModel.Series[0] as ColumnSeries;
                    if (columnSeries != null)
                    {
                        columnSeries.Items.Add(s);
                    }
                }
                var    sum = _sumPoints.ToArray();
                double v   = sum.Sum();
                if (Math.Abs(v) < double.Epsilon * 100)
                {
                    v = 1;
                }
                sum = sum.Select(k => 100 * k / v).ToArray();
                foreach (var s in GenerateColumns(category - 1, sum))
                {
                    var columnSeries = SumModel.Series[0] as ColumnSeries;
                    if (columnSeries != null)
                    {
                        columnSeries.Items.Add(s);
                    }
                }
            }

            CountModel  = CountModel;
            PointsModel = PointsModel;
            SumModel    = SumModel;
            CountModel.InvalidatePlot(true);
            PointsModel.InvalidatePlot(true);
            SumModel.InvalidatePlot(true);
        }
示例#8
0
 public void Add(PointsModel pointsModel, out string strErrMsg)
 {
     SqlParameter[] parameters = new SqlParameter[] {
         new SqlParameter("@id", SqlDbType.Int, 4),
         new SqlParameter("@PointId", SqlDbType.VarChar, 20),
         new SqlParameter("@x", SqlDbType.Float, 8),
         new SqlParameter("@y", SqlDbType.Float, 8)
     };
     parameters[0].Value = pointsModel.id;
     parameters[1].Value = pointsModel.PointId;
     parameters[2].Value = pointsModel.x;
     parameters[3].Value = pointsModel.y;
     DB.RunProcedureByInt("Shine_Points_Add", parameters, out strErrMsg);
 }
示例#9
0
        private IUserResponseModel SelectUserData(Account account)
        {
            UserResponseModel userResponseModel = new UserResponseModel();

            userResponseModel.UserId    = account.Id;
            userResponseModel.UserEmail = account.Email;
            userResponseModel.UserName  = account.UserName;

            PointsModel pointsModel = _context.Points.FirstOrDefault(x => x.Account.Id == account.Id);

            userResponseModel.UserPoints = pointsModel != null ? pointsModel.Value : 0.0;

            return(userResponseModel);
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <param name="IsManually">是否手動新增</param>
        public static void SetItem(PointsModel item, bool IsManually = false)
        {
            SQLData.Database    db       = new SQLData.Database(WebInfo.Conn);
            SQLData.TableObject tableObj = db.GetTableObject("Points");

            tableObj.GetDataFromObject(item);

            DateTime now   = DateTime.Now;
            string   sql   = "Select 1 From Points Where ID = " + item.ID;
            bool     isNew = db.GetFirstValue(sql) == null;

            tableObj["SiteID"]       = item.SiteID;
            tableObj["MemberShipID"] = item.MemberShipID;
            tableObj["Remark"]       = string.IsNullOrEmpty(item.Remark) ? "" : item.Remark;
            tableObj["Description"]  = string.IsNullOrEmpty(item.Description) ? "" : item.Description;
            tableObj["Point"]        = item.Point;
            tableObj["IsManually"]   = IsManually;
            tableObj["PointType"]    = item.PointType;

            if (isNew)
            {
                if (item.Creator == 0)
                {
                    tableObj["Creator"] = Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id;
                }
                tableObj["CreateTime"] = now;

                tableObj.Insert();
            }
            else
            {
                tableObj.Remove("ID");
                tableObj.Remove("SiteID");
                tableObj.Remove("Creator");
                tableObj.Remove("CreateTime");

                Common.Member curUser = Common.Member.Current;
                tableObj["Modifier"]   = curUser == null ? Areas.Backend.Models.DataAccess.MemberDAO.SysCurrent.Id : curUser.ID;
                tableObj["ModifyTime"] = now;

                tableObj.Update(item.ID);
            }
        }
示例#11
0
        public async Task <IResponse> GetPointsValue(string userId)
        {
            GetPointsValueResponse getPointsValueResponse = new GetPointsValueResponse();

            Account account = await _userManager.FindByIdAsync(userId);

            if (account == null)
            {
                List <string> errors = new List <string>();
                errors.Add("UserId does not exist.");
                getPointsValueResponse.Errors = errors;
            }
            else
            {
                PointsModel points = await _context.Points.SingleOrDefaultAsync(x => x.Account.Id == userId);

                getPointsValueResponse.Points = points.Value;
            }
            return(getPointsValueResponse);
        }
示例#12
0
        public ActionResult Edit(long siteId, long menuId, long memberID, PointsModel item)
        {
            ViewBag.SiteID   = siteId;
            ViewBag.MenuID   = menuId;
            ViewBag.MemberID = memberID;

            item.MemberShipID = memberID;
            item.SiteID       = siteId;
            if (item.PointType == 1)
            {
                item.Point  = -item.Point;
                item.Remark = "平台管理者主動扣除點數";
            }
            else if (item.PointType == 0)
            {
                item.Remark = "平台管理者協助增加點數";
            }
            PointsDAO.SetItem(item, true);
            ViewBag.Exit = true;
            return(View(item));
        }
示例#13
0
        public WindowViewModel()
        {
            IsEnableToPress = true;
            ExecuteTask     = new Command(async() =>
            {
                if (!int.TryParse(PointsCount, out pointsCountNum))
                {
                    return;
                }
                IsEnableToPress   = false;
                IsWorking         = true;
                ClassModel result = null;
                var model         = new PointsModel(pointsCountNum);
                await Task.Run(() =>
                {
                    result = model.GeneratePoints();
                });
                //ImageSource = await Task.FromResult(Draw(result.Item1));
                Tuple <List <ClassModel>, bool> redrawResult = null;
                List <Points> allPointses = new List <Points>(result.ClassPoints);
                var classList             = new List <ClassModel>();
                classList.Add(result);
                while (true)
                {
                    await Task.Run(() =>
                    {
                        redrawResult = model.GenerateClasses(classList, allPointses);
                    });

                    if (!redrawResult.Item2)
                    {
                        break;
                    }
                }
                ImageSource     = await Task.FromResult(Draw(redrawResult.Item1));
                IsWorking       = false;
                IsEnableToPress = true;
            });
        }
示例#14
0
 public WindowViewModel()
 {
     IsEnableToPress = true;
     ExecuteTask     = new Command((async() =>
     {
         if (!ConvertCheckingWrite())
         {
             return;
         }
         IsEnableToPress = false;
         IsWorking = true;
         Tuple <List <ClassModel>, List <Points> > result = null;
         var model = new PointsModel(pointsCountNum, classCountNum);
         await Task.Run(() =>
         {
             result = model.ExecuteFirstDrawing();
         });
         await Task.Delay(200);
         ImageSource = await Task.FromResult(Draw(result.Item1));
         Tuple <List <ClassModel>, bool> redrawResult = null;
         while (true)
         {
             await Task.Run(() =>
             {
                 redrawResult = model.RedrawPoints(result.Item2, result.Item1);
             });
             if (!redrawResult.Item2)
             {
                 break;
             }
             ImageSource = await Task.FromResult(Draw(redrawResult.Item1));
             await Task.Delay(200);
         }
         IsWorking = false;
         IsEnableToPress = true;
     }));
 }
示例#15
0
 private void Construct(PointsModel pointsModel)
 {
     _pointsModel = pointsModel;
 }
示例#16
0
        public async Task <IResponse> ExchangeItem([FromBody] ItemExchangeViewModel itemExchangeViewModel)
        {
            ItemExchangeResponse itemExchangeResponse = new ItemExchangeResponse();
            List <string>        errors = new List <string>();

            Item item = await _context.Items.Include(x => x.Category).Include(x => x.OwnerAccount).FirstOrDefaultAsync(x => x.Id == itemExchangeViewModel.ItemId);

            if (item != null)
            {
                Account newOwnerAccount =
                    await _userManager.FindByIdAsync(itemExchangeViewModel.NewOwnerAccountId);

                if (newOwnerAccount != null)
                {
                    PointsModel points = await _context.Points.SingleOrDefaultAsync(x => x.Account == newOwnerAccount);

                    if (points.Value >= itemExchangeViewModel.PointValue)
                    {
                        await _pointManager.RemoveFromUserAsync(newOwnerAccount, itemExchangeViewModel.PointValue);

                        Account oldOwnerAccount = item.OwnerAccount;
                        item.OwnerAccount = newOwnerAccount;

                        _context.Items.Update(item);
                        await _context.SaveChangesAsync();

                        ItemExchangeModel itemExchangeModel = new ItemExchangeModel
                        {
                            Item            = item,
                            OldOwnerAccount = oldOwnerAccount,
                            NewOwnerAccount = item.OwnerAccount,
                            PointValue      = itemExchangeViewModel.PointValue
                        };

                        ItemExchange itemExchange = new ItemExchange(_context);
                        itemExchange.Set(itemExchangeModel);
                        itemExchangeResponse = await itemExchange.CommitAsync();

                        errors.Add("Item checked out successfully");
                    }
                    else
                    {
                        errors.Add($"Not enough points for user :{newOwnerAccount.UserName}");
                    }
                }
                else
                {
                    errors.Add("User not found.");
                }
            }
            else
            {
                errors.Add("Item not found.");
            }
            if (errors.Count > 0)
            {
                itemExchangeResponse.Errors = errors;
            }
            else
            {
                itemExchangeResponse.Errors = null;
            }


            return(itemExchangeResponse);
        }
示例#17
0
 public void Add(PointsModel pointsModel, out string strErrMsg)
 {
     dal.Add(pointsModel, out strErrMsg);
 }
示例#18
0
        public async Task <bool> GetUserStats(UserModel user, bool addToLog = false, bool isRetry = false)
        {
            if (requestCount++ > maxRequestsPerSecond)
            {
                logger.LogInformation("Max request coun exceed, waiting until continuing...");
                Thread.Sleep(1_000);
                requestCount = 0;
            }

            if (user.SummonerId == null)
            {
                await GetSummonerID(user);
            }

            RiotAPIAccessLayer.Models.PointsModel[] pointsRes;

            try
            {
                pointsRes = await wrapper.GetSummonerPoints(user.Server, user.SummonerId);
            }
            catch (Exception e)
            {
                if (e is ResponseException &&
                    !(e as ResponseException).Response.IsSuccessStatusCode &&
                    (e as ResponseException).Response.StatusCode != HttpStatusCode.TooManyRequests)
                {
                    // If the data can not be fetched by the summoner ID saved in the databse,
                    // then firstly try to collect the user ID of the user from the API again
                    // and retry this function with isRetry passed as true.
                    // If isRetry is true, the user will be 'Watch' flag of the user will be set
                    // to false to prevent further errors.
                    if (!isRetry)
                    {
                        logger.LogInformation($"Requesting stats of user '{user.Username}' failed: ${(e as ResponseException).Response.StatusCode}");
                        logger.LogInformation($"Trying to refresh users ID and retry getting stats...");
                        await GetSummonerID(user);

                        return(await GetUserStats(user, addToLog, true));
                    }
                    else
                    {
                        user.Watch = false;
                        logger.LogError("retry getting stats failed - settings 'Watch' flag to false");
                        dal.Update(user);
                    }
                }
                else
                {
                    logger.LogError($"An unexpected error occured during request: {e.Message}");
                }

                return(false);
            }


            var pointsDb = await dal.GetPointsAsync(user.Id);

            Array.ForEach(pointsRes, p =>
            {
                var pChamp = pointsDb.FirstOrDefault(pdb => pdb.ChampionId == p.ChampionId);

                if (pChamp == null)
                {
                    pChamp = new PointsModel
                    {
                        ChampionId     = p.ChampionId,
                        ChampionLevel  = p.ChampionLevel,
                        ChampionPoints = p.ChampionPoints,
                        LastPlayed     = TimeUtils.UnixToDateTime(p.LastPlayed),
                        User           = user,
                    };

                    dal.Add(pChamp);
                }
                else
                {
                    pChamp.ChampionLevel  = p.ChampionLevel;
                    pChamp.ChampionPoints = p.ChampionPoints;
                    pChamp.LastPlayed     = TimeUtils.UnixToDateTime(p.LastPlayed);
                    pChamp.Updated        = DateTime.Now;

                    dal.Update(pChamp);
                }

                if (addToLog)
                {
                    var pointsLog = new PointsLogModel
                    {
                        ChampionLevel  = p.ChampionLevel,
                        ChampionId     = p.ChampionId,
                        ChampionPoints = p.ChampionPoints,
                        User           = user,
                    };

                    dal.Add(pointsLog);
                }
            });

            await dal.CommitChangesAsync();

            logger.LogInformation("Changed commited to database");

            return(true);
        }