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()); }
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)); } }
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); } }
public ActionResult _AvailableMoneyForm() { AvailableMoneyCreateViewModel model = AvailableMoneyQueries.GetInitializedAvailableMoney(UserQueries.GetCurrentUsername()); return(PartialView(model)); }