示例#1
0
        public static bool DeleteFlight(int code)
        {
            var user = UserSession.Current.User;

            if (user != null)
            {
                var repo   = new FlightRepository(false, actionCode: (int)Constants.FlightAction.Code, code: code);
                var flight = repo.List.FirstOrDefault() ?? new Flight();
                var result = repo.DeleteFlight();
                if (result)
                {
                    var task = new Task(() => InformationManager.DeleteFlight(flight.Plan, flight));
                    task.Start();
                    UpdatePlan(flight.Plan, true);
                }
                return(result);
            }
            throw new Exception();
        }
示例#2
0
        public static bool BudgetReplenishment(int?code, decimal budget)
        {
            var user = UserSession.Current.User;

            if (user != null)
            {
                var userRepo = new UserRepository((int)Constants.UserAction.Code);
                if (code == null)
                {
                    user       = userRepo.GetUser(user.Code);
                    user.Cash += budget;
                    var task = new Task(() => InformationManager.BudgetReplenishment(user, budget));
                    task.Start();
                    return(UserManager.UpdateUserData(user) != null);
                }
                else
                {
                    var userData = userRepo.GetUser(code.Value);
                    if (userData != null)
                    {
                        userData.Cash += budget;
                        userRepo.UpdateUserData(userData.Code, userData, new List <int>()
                        {
                            (int)Constants.UserField.Cash
                        });

                        user           = userRepo.GetUser(user.Code);
                        user.Cash     -= budget;
                        user.LastLogin = Constants.TotalMilliseconds;
                        UserManager.UpdateUserData(user);

                        var task = new Task(() => InformationManager.MoneyTransfer(user, userData, budget));
                        task.Start();
                        return(true);
                    }
                }

                return(false);
            }
            throw new NotImplementedException();
        }
示例#3
0
        public static bool CreatePlan(Plan plan)
        {
            var user = UserSession.Current.User;

            if (user != null)
            {
                plan.OwnerCode  = user.Code;
                plan.CreateDate = Constants.TotalMilliseconds;
                plan.LastUpdate = Constants.TotalMilliseconds;
                plan.Status     = (int)Constants.WorkflowStatus.InPlanned;
                var repo = new PlanRepository();
                var code = repo.InsertData(plan);

                if (code > 0)
                {
                    var task = new Task(() => InformationManager.CreatePlan(new Plan(code, plan), user.FamilyCode));
                    task.Start();
                    return(true);
                }
            }
            throw new Exception();
        }
示例#4
0
        public static bool UndeletePlan(int code)
        {
            var user = UserSession.Current.User;

            if (user != null)
            {
                var repo = new PlanRepository(false, (int)Constants.PlanAction.Code, code);
                if (repo.List.Any())
                {
                    var plan = repo.List.FirstOrDefault();
                    if (plan.OwnerCode == user.Code)
                    {
                        if (UpdateStatus(plan, repo, (int)Constants.WorkflowStatus.InPlanned) != null)
                        {
                            var task = new Task(() => InformationManager.UnDeletePlan(plan, user.FamilyCode));
                            task.Start();
                            return(true);
                        }
                    }
                }
            }
            throw new Exception();
        }