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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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)); } }
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); } }
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); } }
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); } }
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)); } }