Esempio n. 1
0
        public Dictionary <string, dynamic> CheatMoney(string token)
        {
            try
            {
                var user = db.Users.Where(u => u.Token == token).FirstOrDefault();
                var id   = user.Id;

                var defaultCard = db.Cards.Where(c => c.OwnerId == id && c.IsDefault == true).FirstOrDefault();

                defaultCard.Balance = 999999.9f;
                db.SaveChanges();

                return(new Dictionary <string, dynamic>()
                {
                    { "succeed", true }
                });
            }
            catch (Exception e)
            {
                return(new Dictionary <string, dynamic>()
                {
                    { "succeed", false }
                });
            }
        }
Esempio n. 2
0
        public Dictionary <string, dynamic> CreateDonation(string token, string receiver_card_token /*if equals "null", so use default*/, string title, string description)
        {
            try
            {
                var  user         = db.Users.Where(u => u.Token == token).FirstOrDefault();
                Card receiverCard = new Card();

                if (receiver_card_token == "null")
                {
                    receiverCard = db.Cards.Where(c => c.OwnerId == user.Id && c.IsDefault == true).FirstOrDefault();
                }
                else
                {
                    receiverCard = db.Cards.Where(c => c.OwnerId == user.Id && c.CardToken == receiver_card_token).FirstOrDefault();
                }

                string donationToken = "";
                do
                {
                    donationToken = TokenGenerator.Generate(baseTokenLength);
                } while (db.Donations.Where(d => d.DonationToken == donationToken).Count() != 0);

                Donation d = new Donation()
                {
                    DonationToken  = donationToken,
                    OwnerId        = user.Id,
                    ReceiverCardId = receiverCard.Id,
                    Title          = title,
                    Description    = description
                };

                db.Donations.Add(d);
                db.SaveChanges();

                return(new Dictionary <string, dynamic>()
                {
                    { "success", true },
                    { "donation_token", donationToken }
                });
            }
            catch (Exception e)
            {
                return(new Dictionary <string, dynamic>()
                {
                    { "success", false },
                    { "donation_token", "" },
                    { "err", e.InnerException.Message }
                });
            }
        }
Esempio n. 3
0
 public void AddUser(User user)
 {
     using (var context = new CustomDBContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 public void SaveUser(User user)
 {
     using (var context = new CustomDBContext())
     {
         context.Users.Attach(user);
         context.Entry(user).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 5
0
        public Dictionary <string, dynamic> Register(string username, string email, string phone, string password)
        {
            string hashedPassword = Hasher.StringToSHA256(password);

            if (db.Users.Where(u => u.Username == username || u.Email == email).ToList().Count == 0)
            {
                // so we can register this user
                string token = "";
                do
                {
                    token = TokenGenerator.Generate(baseTokenLength);
                } while (db.Users.Where(u => u.Token == token).Count() != 0);

                db.Users.Add(new User()
                {
                    Username = username,
                    Email    = email,
                    Phone    = phone,
                    Password = hashedPassword,
                    Token    = token
                });
                db.SaveChanges();

                return(new Dictionary <string, dynamic>()
                {
                    { "registered", true }
                });
            }
            else
            {
                // we cant register new user
                return(new Dictionary <string, dynamic>()
                {
                    { "registered", false }
                });
            }
        }
Esempio n. 6
0
 public void Create(User entity)
 {
     DbSet.Add(entity);
     _dbContext.SaveChanges();
 }
Esempio n. 7
0
 public void Add(T entity)
 {
     dbSet.Add(entity);
     dbContext.SaveChanges();
 }