Exemplo n.º 1
0
 public bool PayOff(Payoff payoff)
 {
     using (var dbContext = new TextLandDbContext())
     {
         dbContext.Users.Attach(payoff.RequestingUser);
         var newPayoff = dbContext.Payoffs.Add(payoff);
         dbContext.SaveChanges();
         return((newPayoff != null) ? true : false);
     }
 }
Exemplo n.º 2
0
 public bool DeleteUser(User userToDelete, string password)
 {
     using (var dbContext = new TextLandDbContext())
     {
         dbContext.Users.Attach(userToDelete);
         dbContext.Users.Remove(userToDelete);
         dbContext.SaveChanges();
         return((GetUserById(userToDelete.UserId) == null)? true : false);
     }
 }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public User RegisterUser(User user)
        {
            using (var dbContext = new TextLandDbContext())
            {
                var existingUser = GetUserByEmail(user.Email);
                if (existingUser != null)
                {
                    return(null);
                }

                var newUser = dbContext.Users.Add(user);
                dbContext.SaveChanges();
                return(newUser);
            }
        }
Exemplo n.º 7
0
        public Payoff RealizePayoff(int id)
        {
            using (var dbContext = new TextLandDbContext())
            {
                var payoffToRealize = GetUndonePayoffs().SingleOrDefault(x => x.PayoffId == id);
                if (payoffToRealize == null)
                {
                    return(null);
                }

                dbContext.Payoffs.Attach(payoffToRealize);
                payoffToRealize.IsDone = true;
                dbContext.SaveChanges();

                return(GetPayoffById(id));
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        public Order AddTextToOrder(Order madeOrder)
        {
            using (var dbContext = new TextLandDbContext())
            {
                if (madeOrder == null)
                {
                    return(null);
                }

                var order = GetOrderById(madeOrder.OrderId);

                dbContext.Orders.Attach(order);
                order.Content       = madeOrder.Content;
                order.IsDone        = madeOrder.IsDone;
                order.ExecutingUser = madeOrder.ExecutingUser;
                dbContext.Users.Attach(madeOrder.ExecutingUser);
                dbContext.SaveChanges();

                return(GetOrderById(madeOrder.OrderId));
            }
        }