Beispiel #1
0
 public override void Initialize()
 {
     User usr = GetConcretEntity<User>();
     UserInfo = ApplicationVM.Cache.UserInfos.FirstOrDefault(i => i.User_Id == usr.Id &&
         (i.Application_Id == ApplicationVM.ApplicationId || i.Application_Id == BuiltIns.AllApplication.Id));
     if (UserInfo != null)
     {
         if (UserInfo.Money.HasValue)
         {
             Money = UserInfo.Money.Value;
         }
         if (UserInfo.Score.HasValue)
         {
             Score = UserInfo.Score.Value;
         }
         RoleVM = ApplicationVM.LocalCache.AllRoleVMs.FirstOrDefault(r => r.Id == UserInfo.Role_Id);
     }
    
     var rrs = ApplicationVM.LocalCache.AllRoomRoleVMs.Where(rr => rr.UserId == Id);
     if (rrs != null)
     {
         RoomRoleVMs = new System.Collections.ObjectModel.ObservableCollection<RoomRoleViewModel>(rrs);
     }
     base.Initialize();
 }
Beispiel #2
0
 public ClientUserModel(User user, UserApplicationInfo userInfo)
     : base(user)
 {
     if (userInfo != null)
     {
         Application_Id = userInfo.Application_Id;
         User_Id = userInfo.User_Id;
         if (userInfo.AgentMoney.HasValue)
             AgentMoney = userInfo.AgentMoney;
         else
             AgentMoney = 0;
         if (userInfo.Money.HasValue)
             Money = userInfo.Money;
         else
             Money = 0;
         if (userInfo.Score.HasValue)
             Score = userInfo.Score;
         else
             Score = 0;
         Role_Id = userInfo.Role_Id;
     }
 }
Beispiel #3
0
 public ExchangeHistory AddExchangeHistory(int appid, int userId, string token, ExchangeHistory history)
 {
     try
     {
         CheckToken(appid, userId, token);
         CheckCommand(appid, history.Application_Id, userId, BuiltIns.ExchangeCommand.Id, BuiltIns.AllRole.Id);
         using (TransactionScope scope = new TransactionScope())
         {
             modelAccesser.Add<ExchangeHistory>(history);
             UserApplicationInfo uInfo = new UserApplicationInfo { User_Id = history.User_Id, Application_Id = history.Application_Id };
             modelAccesser.Get<UserApplicationInfo>(uInfo);
             uInfo.Score -= history.Score;
             uInfo.Money -= history.Money;
             modelAccesser.Update<UserApplicationInfo>(uInfo);
             scope.Complete();
         }
         return history;
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #4
0
 public void CancelExchangeCache(int appid, int userId, string token, List<ExchangeHistory> history)
 {
     try
     {
         if (history.Count > 0)
         {
             CheckToken(appid, userId, token);
             CheckCommand(appid, history[0].Application_Id, userId, BuiltIns.ExchangeCommand.Id, BuiltIns.AllRole.Id);
             using (TransactionScope scope = new TransactionScope())
             {
                 history.ForEach(h =>
                     {
                         if (h.Status <= 2)
                         {
                             UserApplicationInfo uInfo = new UserApplicationInfo { User_Id = h.User_Id, Application_Id = h.Application_Id };
                             modelAccesser.Get<UserApplicationInfo>(uInfo);
                             uInfo.Score += h.Score;
                             uInfo.Money += h.Money;
                             modelAccesser.Update<UserApplicationInfo>(uInfo);
                             modelAccesser.Delete<ExchangeHistory>(h);
                         }
                     });
                 scope.Complete();
             }
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #5
0
 public bool Deposit(int appid, int userId, string token, int depositAppid, int id, int money, bool isAgent)
 {
     CheckToken(appid, userId, token);
     CheckCommand(appid, depositAppid, userId, isAgent ? BuiltIns.AgentDepositCommand.Id : BuiltIns.UserDepositCommand.Id, BuiltIns.AllRole.Id);
     try
     {
         using (TransactionScope scope = new TransactionScope())
         {
             UserApplicationInfo user = new UserApplicationInfo { Application_Id = depositAppid, User_Id = id };
             modelAccesser.Get<UserApplicationInfo>(user);
             if (isAgent)
             {
                 if (!user.AgentMoney.HasValue)
                 {
                     user.AgentMoney = 0;
                 }
                 user.AgentMoney += money;
             }
             else
             {
                 if (!user.Money.HasValue)
                 {
                     user.Money = 0;
                 }
                 user.Money += money;
             }
             modelAccesser.Update<UserApplicationInfo>(user);
             DepositHistory history = new DepositHistory { Application_Id = depositAppid, IsAgent = isAgent, Money = money, OptUser_Id = userId, User_Id = id, Time = DateTime.Now };
             modelAccesser.Add<DepositHistory>(history);
             scope.Complete();
             return true;
         }
     }
     catch { return false; }
 }
Beispiel #6
0
 public void ScoreExchange(int appid, int userId, string token, int scoreExchangeAppid, int id, int score, int money)
 {
     try
     {
         CheckToken(appid, userId, token);
         //ToDo: Check everyone can exchange score?
         //CheckCommand(appid, scoreExchangeAppid, userId, BuiltIns.ScoreToMoneyCommand.Id, BuiltIns.AllRole.Id);
         using (TransactionScope scope = new TransactionScope())
         {
             UserApplicationInfo info = new UserApplicationInfo { Application_Id = scoreExchangeAppid, User_Id = id };
             modelAccesser.Get(info);
             if (!info.Score.HasValue || info.Score < score)
             {
                 throw new FaultException<ScoreNotEnoughtException>(new ScoreNotEnoughtException());
             }
             info.Score -= score;
             if (!info.Money.HasValue)
             {
                 info.Money = 0;
             }
             info.Money += money;
             modelAccesser.Update(info);
             ExchangeHistory history = new ExchangeHistory { Application_Id = scoreExchangeAppid, OptUser_Id = userId, User_Id = id, Score = score, Money = money, ApplyTime = DateTime.Now, SettlementTime=DateTime.Now,Status= 2};
             modelAccesser.Add<ExchangeHistory>(history);
             scope.Complete();
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #7
0
 public void ScoreDeposit(int appid, int userId, string token, int depositAppid, int id, int score)
 {
     try
     {
         CheckToken(appid, userId, token);
         CheckCommand(appid, depositAppid, userId, BuiltIns.ScoreDepositCommand.Id, BuiltIns.AllRole.Id);
         using (TransactionScope scope = new TransactionScope())
         {
             UserApplicationInfo info = new UserApplicationInfo { Application_Id = depositAppid, User_Id = id };
             modelAccesser.Get(info);
             if (!info.Score.HasValue)
             {
                 info.Score = 0;
             }
             info.Score += score;
             modelAccesser.Update(info);
             DepositHistory history = new DepositHistory { Application_Id = depositAppid, OptUser_Id = userId, User_Id = id, Score = score, Time = DateTime.Now };
             modelAccesser.Add<DepositHistory>(history);
             scope.Complete();
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #8
0
 public void UpdateUserInfo(int appid, int userId, string token, UserApplicationInfo info)
 {
     try
     {
         CheckToken(appid, userId, token);
         if (userId != info.User_Id)
         {
             CheckCommand(appid, info.Application_Id, userId, BuiltIns.DefineUserCommand.Id, BuiltIns.AllRole.Id);
         }
         using (TransactionScope scope = new TransactionScope())
         {
             UserApplicationInfo oldInfo = new UserApplicationInfo { Application_Id = info.Application_Id, User_Id = info.User_Id };
             modelAccesser.Get<UserApplicationInfo>(oldInfo);
             if (oldInfo.Loaded)
             {
                 if (oldInfo.Role_Id != info.Role_Id)
                 {
                     CheckCommand(appid, info.Application_Id, userId, BuiltIns.UserRoleUpDownCommand.Id, BuiltIns.AllRole.Id);
                     UserIdList idList = new UserIdList { User_Id = info.User_Id, Application_Id = info.Application_Id };
                     modelAccesser.Get<UserIdList>(idList);
                     if (idList.Loaded)
                     {
                         idList.Role_Id = info.Role_Id;
                         idList.IsUsed = true;
                         modelAccesser.Update<UserIdList>(idList);
                     }
                     else
                     {
                         idList.IsUsed = true;
                         idList.Owner_Id = -1;
                         idList.Role_Id = info.Role_Id;
                         modelAccesser.Add<UserIdList>(idList);
                     }
                 }
                 modelAccesser.Update<UserApplicationInfo>(info);
                 scope.Complete();
             }
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #9
0
 public UserApplicationInfo AddUserInfo(int appid, int userId, string token, UserApplicationInfo info)
 {
     try
     {
         CheckToken(appid, userId, token);
         CheckCommand(appid, info.Application_Id, userId, BuiltIns.DefineUserCommand.Id, BuiltIns.AllRole.Id);
         modelAccesser.Add<UserApplicationInfo>(info);
         return info;
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #10
0
 public void DeleteUserInfo(int appid, int userId, string token, int id, int userInfoAppid)
 {
     try
     {
         CheckToken(appid, userId, token);
         CheckCommand(appid, userInfoAppid, userId, BuiltIns.DefineUserCommand.Id, BuiltIns.AllRole.Id);
         UserApplicationInfo info = new UserApplicationInfo { Application_Id = userInfoAppid, User_Id = id };
         modelAccesser.Delete<UserApplicationInfo>(info);
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
 }
Beispiel #11
0
 public UserApplicationInfo GetUserInfo(int appid, int userId, string token, int id, int userInfoAppid)
 {
     try
     {
         CheckToken(appid, userId, token);
         UserApplicationInfo info = new UserApplicationInfo { Application_Id = userInfoAppid, User_Id = id };
         modelAccesser.Get<UserApplicationInfo>(info);
         if (!info.Loaded)
         {
             info.Application_Id = BuiltIns.AllApplication.Id;
             modelAccesser.Get(info);
             if (info.Loaded)
             {
                 return info;
             }
         }
         else
         {
             return info;
         }
     }
     catch (Exception)
     {
         throw new DatabaseException();
     }
     return null;
 }
Beispiel #12
0
        public User Register(int appid, int userId, string account, string pwd, int sex)
        {
            try
            {
                User newUser = null;
                using (TransactionScope scope = new TransactionScope())
                {
                    var userIdList = new UserIdList { Application_Id = appid, User_Id = userId };
                    modelAccesser.Get(userIdList);
                    if (!userIdList.Loaded)
                    {
                        userIdList.Application_Id = BuiltIns.AllApplication.Id;
                        userIdList.User_Id = userId;
                        modelAccesser.Get(userIdList);
                    }
                    if (userIdList.Loaded)
                    {
                        userIdList.IsUsed = true;
                        modelAccesser.Update<UserIdList>(userIdList);

                        newUser = new User { Id = userId, ApplicationCreated_Id = appid, Name = account, NickName = account, Password = pwd, Gender = sex == 0 };
                        modelAccesser.Add<User>(newUser);
                        UserApplicationInfo userInfo = new UserApplicationInfo { Application_Id = appid, Role_Id = BuiltIns.RegisterUserRole.Id, User_Id = userId, Money = 0, AgentMoney = 0, Score = 0 };
                        modelAccesser.Add<UserApplicationInfo>(userInfo);
                    }
                    scope.Complete();
                }

                return newUser;
            }
            catch (Exception)
            {
                throw new DatabaseException();
            }
        }
 public void UpdateUserInfo(int userId, string token, YoYoStudio.Model.Core.UserApplicationInfo info)
 {
     client.UpdateUserInfo(application_Id, userId, token, info);
 }
 public YoYoStudio.Model.Core.UserApplicationInfo AddUserInfo(int userId, string token, YoYoStudio.Model.Core.UserApplicationInfo info)
 {
     return(client.AddUserInfo(application_Id, userId, token, info));
 }
Beispiel #15
0
 public UserInfoModel(UserApplicationInfo info):base(info)
 {
     if (info != null)
     {
         Application_Id = info.Application_Id;
         User_Id = info.User_Id;
         AgentMoney = info.AgentMoney;
         Money = info.Money;
         Score = info.Score;
         Role_Id = info.Role_Id;
     }
 }