コード例 #1
0
 public double ResetAccount(User user)
 {
     using (var dbContext = new TextLandDbContext())
     {
         dbContext.Users.Attach(user);
         user.AccountForCompletedOrders = 0;
         dbContext.Entry(user).Property(x => x.AccountForCompletedOrders).IsModified = true;
         dbContext.SaveChanges();
         return(GetUserById(user.UserId).AccountForCompletedOrders);
     }
 }
コード例 #2
0
        public bool AcceptOrder(Order order)
        {
            using (var dbContext = new TextLandDbContext())
            {
                order.IsPaid = true;
                dbContext.Orders.Attach(order);
                dbContext.Entry(order).Property(x => x.IsPaid).IsModified = true;

                dbContext.Users.Attach(order.ExecutingUser);
                order.ExecutingUser.AccountForCompletedOrders += order.Value;

                dbContext.SaveChanges();
                return((GetOrderById(order.OrderId).IsPaid == true) ? true : false);
            }
        }
コード例 #3
0
        public Order AddOrder(Order order)
        {
            using (var dbContext = new TextLandDbContext())
            {
                if (order.AddingUser != null && !dbContext.Users.Local.Contains(order.AddingUser))
                {
                    dbContext.Users.Attach(order.AddingUser);
                    dbContext.Entry(order.AddingUser).State = EntityState.Modified;
                }

                var newOrder = dbContext.Orders.Add(order);
                dbContext.SaveChanges();
                return(newOrder);
            }
        }
コード例 #4
0
        public bool RechargeAccount(int userId, double amount)
        {
            using (var dbContext = new TextLandDbContext())
            {
                var user = GetUserById(userId);
                if (user == null)
                {
                    return(false);
                }

                user.AccountForAddingOrders += amount;
                dbContext.Users.Attach(user);
                dbContext.Entry(user).Property(x => x.AccountForAddingOrders).IsModified = true;
                dbContext.SaveChanges();
                return(true);
            }
        }
コード例 #5
0
        public User ChangeUserData(User changedUser)
        {
            using (var dbContext = new TextLandDbContext())
            {
                var modifyingUser = GetUserById(changedUser.UserId);
                if (modifyingUser == null)
                {
                    return(null);
                }

                dbContext.Users.Attach(modifyingUser);
                dbContext.Entry(modifyingUser).CurrentValues.SetValues(changedUser);
                dbContext.SaveChanges();

                var newUser = GetUserById(changedUser.UserId);
                return(newUser);
            }
        }
コード例 #6
0
        public bool SetAdminPrivilage(int userId)
        {
            using (var dbContext = new TextLandDbContext())
            {
                var user = GetUserById(userId);
                if (user == null)
                {
                    return(false);
                }

                user.IsAdmin = true;
                dbContext.Users.Attach(user);
                dbContext.Entry(user).Property(x => x.IsAdmin).IsModified = true;
                dbContext.SaveChanges();

                return((GetUserById(userId).IsAdmin == true) ? true : false);
            }
        }