Пример #1
0
        public async Task <IActionResult> PutPayment([FromRoute] int id, [FromBody] Payment payment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != payment.PaymentId)
            {
                return(BadRequest());
            }


            try
            {
                dbContext.Entry(payment).State = EntityState.Modified;
                await dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                //Console.WriteLine(ex.Message);
                if (!PaymentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public IActionResult ResetPoints()
        {
            foreach (var item in dbContext.Users)
            {
                item.Points = 0.00M;
                dbContext.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            foreach (var item in dbContext.LuckyMes.Where(i => i.User.UserType == 0 && i.Status != "pending" && i.Status != "failed"))
            {
                item.User.Points += (item.Amount * Constants.PointConstant);
                dbContext.Entry(item.User).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            foreach (var item in dbContext.Businesses.Where(i => i.User.UserType == 0 && i.Status != "pending" && i.Status != "failed"))
            {
                item.User.Points += (item.Amount * Constants.PointConstant);
                dbContext.Entry(item.User).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }
            foreach (var item in dbContext.Scholarships.Where(i => i.User.UserType == 0 && i.Status != "pending" && i.Status != "failed"))
            {
                item.User.Points += (item.Amount * Constants.PointConstant);
                dbContext.Entry(item.User).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            }


            dbContext.SaveChanges();
            return(Ok());
        }
        public async Task <IActionResult> PutScholarship([FromRoute] int id, [FromBody] Scholarship Scholarship)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != Scholarship.Id)
            {
                return(BadRequest());
            }

            dbContext.Entry(Scholarship).State = EntityState.Modified;

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ScholarshipExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutBusiness([FromRoute] int id, [FromBody] Business luckyMe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != luckyMe.Id)
            {
                return(BadRequest());
            }

            dbContext.Entry(luckyMe).State = EntityState.Modified;

            try
            {
                await dbContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public ApplicationUser EditUser(UserEditDTO regUser)
        {
            regUser.PhoneNumber = "0" + Misc.NormalizePhoneNumber(regUser.PhoneNumber);
            var user = dbContext.Users.Find(regUser.Id);

            user.UserName           = regUser.Email;
            user.NormalizedUserName = regUser.Email.ToUpper();
            user.FirstName          = regUser.FirstName == "null" ? null : regUser.FirstName;
            user.LastName           = regUser.LastName == "null" ? null : regUser.LastName;
            user.Email           = regUser.Email == "null" ? null : regUser.Email;
            user.NormalizedEmail = regUser.Email.ToUpper();
            user.PhoneNumber     = regUser.PhoneNumber == "null" ? null : regUser.PhoneNumber;

            if (user.MomoDetails == null)
            {
                user.MomoDetails = new MobileMoneyDetails();
            }
            user.MomoDetails.Country  = regUser.Country == "null" ? null : regUser.Country;
            user.MomoDetails.Number   = regUser.MobileMoneyNumber == "null" ? null : regUser.MobileMoneyNumber;
            user.MomoDetails.Network  = regUser.Network == "null" ? null : regUser.Network;
            user.MomoDetails.Currency = regUser.Currency == "null" ? null : regUser.Currency;

            if (user.BankDetails == null)
            {
                user.BankDetails = new BankDetails();
            }
            user.BankDetails.BankName      = regUser.BankName == "null" ? null : regUser.BankName;
            user.BankDetails.AccountNumber = regUser.AccountNumber == "null" ? null : regUser.AccountNumber;
            user.BankDetails.SwiftCode     = regUser.SwiftCode == "null" ? null : regUser.SwiftCode;

            user.PreferedMoneyReceptionMethod = regUser.PreferredReceptionMethod == "null" ? null : regUser.PreferredReceptionMethod;

            try
            {
                dbContext.Entry(user).State             = EntityState.Modified;
                dbContext.Entry(user.BankDetails).State = EntityState.Modified;
                dbContext.Entry(user.MomoDetails).State = EntityState.Modified;
                dbContext.SaveChanges();
                return(user);
            }
            catch
            {
                return(null);
            }
        }
Пример #6
0
        /// <summary>
        /// Returns the Id of the Lucky Me That won
        /// </summary>
        /// <param name="eligibleLuckyMeWinners"></param>
        /// <returns></returns>
        public List <int?> RunLuckyMeAlgorithm(IEnumerable <LuckyMe> eligibleLuckyMeWinners)
        {
            if (eligibleLuckyMeWinners == null || eligibleLuckyMeWinners.Count() < 1)
            {
                return(null);
            }
            //Repeat the luckyme's occurance in the selection list based on the amount staked.
            //The Selection List contains Id's of hte Lucky Me;
            List <int> SelectionList = new List <int>();


            //Get the stakes that are not from dummy users
            var originalStakers     = eligibleLuckyMeWinners.Where(i => i.User.UserType != 2);
            var totalOriginalAmount = originalStakers.Sum(i => i.AmountToWin);


            var fixedWinners = eligibleLuckyMeWinners.Where(i => i.Status.ToLower() == "wins");

            if (fixedWinners.Count() > 0)
            {
                SelectionList.AddRange(fixedWinners.Select(i => i.Id));
            }


            foreach (var item in eligibleLuckyMeWinners)
            {
                //If any item has a status of wins.. put only that item in the list
                //if (item.Status == "wins")
                //{
                //    SelectionList.Clear();
                //    SelectionList.Add(item.Id);
                //    break;
                //}

                if (item.User.UserType != 2 && item.AmountToWin > ((Constants.WinnerTreshold) * totalOriginalAmount))
                {
                    continue;
                }
                //Divide staked amount by possible stake amount
                //This is for assigning winning probabilities to users with higher stake amount
                //var flooredAmount = item.Amount / Settings.LuckyMeStakes[0];
                //for (var i = flooredAmount; i > 0; i--)
                //{
                SelectionList.Add(item.Id);
                //  }
            }


            //Choose a winner randomly
            //Get the list length
            int         selectionListLength = SelectionList.Count;
            List <int?> WinnerIds           = new List <int?>();

            //choose a random index between 0 and the list count inclusive
            if (selectionListLength > 0)
            {
                //Get count of potential winners
                var winnersCounts = DataHub.GetWinnersCount(eligibleLuckyMeWinners.Count());

                //Iterate over the potential winner indices in the selection list
                for (int i = 0; i < winnersCounts; i++)
                {
                    selectionListLength = SelectionList.Count;
                    if (selectionListLength < 1)
                    {
                        break;
                    }
                    //Get the random winner
                    int selectedWinnerIndex = new Random().Next(0, selectionListLength - 1);
                    //Add the winner's Id to the List
                    WinnerIds.Add(SelectionList[selectedWinnerIndex]);
                    //Remove the winner from the list
                    SelectionList.RemoveAt(selectedWinnerIndex);
                }
            }

            //Set Winner and set Loosers
            foreach (var item in eligibleLuckyMeWinners)
            {
                var user = item.User;
                //var user = context.Users.Where(u => u.Id == item.UserId).Include("BankDetails").Include("MomoDetails").FirstOrDefault();
                item.DateDeclared = DateTime.Now.ToLongDateString();
                if (WinnerIds.Contains(item.Id))
                {
                    item.Status = "won";


                    try
                    {
                        if (user.UserType == 0)
                        {
                            MessagingService.SendMail($"{user.FirstName} {user.LastName}", user.Email, "Ntoboafund Winner", $"Congratulations {user.FirstName} {user.LastName}, your {item.Period} Ntoboa of {item.Amount} Cedi(s) on {item.Date} has yielded an amount of {item.AmountToWin} Cedi(s) which would be paid directly into your {user.PreferedMoneyReceptionMethod} account");

                            MessagingService.SendSms(user.PhoneNumber, $"Congratulations {user.FirstName} {user.LastName}, your {item.Period} Luckyme Ntoboa of {item.Amount} Cedi(s) on {item.Date} has yielded an amount of {item.AmountToWin} Cedi(s) which would be paid directly into your {user.PreferedMoneyReceptionMethod} account");

                            MessagingService.SendSms(Constants.MasterNumber, $"{ user.FirstName} { user.LastName} has won {item.AmountToWin} Cedi(s) with {item.Period} Luckyme Ntoboa of {item.Amount} Cedi(s) with Transfer Id {item.TransferId}", "NTB Winners");
                        }
                    }
                    catch
                    {
                    }
                    continue;
                }

                item.Status = "lost";

                if (user.UserType == 0)
                {
                    MessagingService.SendMail($"{user.FirstName} {user.LastName}", user.Email, "Ntoboafund Yeild Failure", $"Sorry {user.FirstName} {user.LastName}, your LuckyMe Ntoboa of {item.Amount} Cedi(s) on {item.Date} has won you {item.Amount * Constants.PointConstant} points. Invest more to increase your chances of winning. Please Try Again");

                    MessagingService.SendSms(user.PhoneNumber, $"Sorry {user.FirstName} {user.LastName}, your LuckyMe Ntoboa of {item.Amount} Cedi(s) on {item.Date} has won you {item.Amount * Constants.PointConstant} points. Invest more to increase your chances of winning. Please Try Again");
                }


                context.Entry(item).State = EntityState.Modified;
            }

            return(WinnerIds);
        }