コード例 #1
0
        public static int CreateAvailableMoney(AvailableMoneyCreateViewModel model, string username)
        {
            Entities entities = new Entities();
            DateTime current  = DateTime.Now;

            Users  user           = entities.Users.Where(x => x.Username.Equals(username)).FirstOrDefault();
            Assets availableMoney = entities.Assets.Where(x => x.Username.Equals(username) &&
                                                          x.AssetType == (int)Constants.Constants.ASSET_TYPE.AVAILABLE_MONEY &&
                                                          !x.DisabledDate.HasValue).OrderBy(x => x.CreatedDate).FirstOrDefault();

            if (availableMoney != null)
            {
                availableMoney.Value = model.AvailableMoney.Value;
                entities.Assets.Attach(availableMoney);
                entities.Entry(availableMoney).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                availableMoney             = new Assets();
                availableMoney.AssetName   = "Tiền mặt có sẵn khởi tạo của " + user.FullName;
                availableMoney.AssetType   = (int)Constants.Constants.ASSET_TYPE.AVAILABLE_MONEY;
                availableMoney.CreatedBy   = Constants.Constants.USER;
                availableMoney.CreatedDate = current;
                availableMoney.StartDate   = current;
                availableMoney.Username    = username;
                availableMoney.Value       = model.AvailableMoney.Value;
                entities.Assets.Add(availableMoney);
            }

            return(entities.SaveChanges());
        }
コード例 #2
0
 public ActionResult _AvailableMoneyForm(AvailableMoneyCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         int result = AvailableMoneyQueries.CreateAvailableMoney(model, UserQueries.GetCurrentUsername());
         if (result > 0)
         {
             return(Content("success"));
         }
         else
         {
             return(Content("failed"));
         }
     }
     else
     {
         return(PartialView(model));
     }
 }
コード例 #3
0
        public static AvailableMoneyCreateViewModel GetInitializedAvailableMoney(string username)
        {
            Entities entities = new Entities();
            AvailableMoneyCreateViewModel viewModel = new AvailableMoneyCreateViewModel();
            Users user = entities.Users.Where(x => x.Username.Equals(username)).FirstOrDefault();

            Assets availableMoney = entities.Assets.Where(x => x.Username.Equals(username) &&
                                                          x.AssetType == (int)Constants.Constants.ASSET_TYPE.AVAILABLE_MONEY &&
                                                          !x.DisabledDate.HasValue).OrderBy(x => x.CreatedDate).FirstOrDefault();

            if (availableMoney != null)
            {
                viewModel.Name           = "Tiền mặt có sẵn khởi tạo của " + user.FullName;
                viewModel.AvailableMoney = availableMoney.Value;
                viewModel.IsInitialized  = UserQueries.IsCompleteInitialized(username);
                return(viewModel);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        public ActionResult _AvailableMoneyForm()
        {
            AvailableMoneyCreateViewModel model = AvailableMoneyQueries.GetInitializedAvailableMoney(UserQueries.GetCurrentUsername());

            return(PartialView(model));
        }