public void AddCash(Guid userid, decimal amount) { var user = this._db.aspnet_Users.Where(m => m.UserId == userid); if (user == null) { throw new Exception("Người dùng không tồn tại"); } if (IsExist(userid)) { var senuseredit = GetById2(userid); senuseredit.AmountBalance = amount; senuseredit.LastPayment = DateTime.UtcNow; this._db.Entry(senuseredit).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); } else { var senuser = new Models.SenUser(); senuser.UserId = userid; senuser.AmountBalance = amount; senuser.LastPayment = DateTime.UtcNow; this._db.SenUsers.Add(senuser); this._db.SaveChanges(); } }
public void UpdateCash(Guid userid) { var senusercash = this._db.SenUserCashs.Where(m => m.UserId == userid).OrderByDescending(m => m.VoucherDate).FirstOrDefault(); var amountcash = this._db.SenUserCashs.Where(m => m.UserId == userid).Select(m => m.Amount).DefaultIfEmpty(0).Sum(); var amountpay = this._db.SenUserPaymentViews.Where(m => m.UserId == userid).Select(m => m.Amount).DefaultIfEmpty(0).Sum(); var amount = amountcash - amountpay; var user = this._db.aspnet_Users.Where(m => m.UserId == userid); if (user == null) { throw new Exception("Người dùng không tồn tại"); } if (IsExist(userid)) { var senuseredit = GetById2(userid); senuseredit.AmountBalance = amount; //senuseredit.LastPayment = DateTime.UtcNow; if (senusercash != null) { senuseredit.LastPayment = senusercash.VoucherDate; } this._db.Entry(senuseredit).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); } else { var senuser = new Models.SenUser(); senuser.UserId = userid; senuser.AmountBalance = amount; //senuser.LastPayment = DateTime.UtcNow; if (senusercash != null) { senuser.LastPayment = senusercash.VoucherDate; } this._db.SenUsers.Add(senuser); this._db.SaveChanges(); } //var senuser = GetById(userid); //senuser.AmountBalance = amountcash - amountpay; //if (senusercash != null) //{ // senuser.LastPayment = senusercash.VoucherDate; //} //this.Update(senuser); }
public int Insert(Models.SenUserView data) { try { this.Validate(data); var _data = new Models.SenUser(); this.MapView2Table(data, _data); this._db.SenUsers.Add(_data); this._db.SaveChanges(); return(data.SenUserId); } catch (Exception) { throw; } }
public Guid InsertByUser(Models.SenUserView data) { try { this.Validate(data); data.UserId = Guid.Parse(Membership.GetUser().ProviderUserKey.ToString()); var _data = new Models.SenUser(); this.MapView2Table(data, _data); this._db.SenUsers.Add(_data); this._db.SaveChanges(); return(data.UserId); } catch (Exception) { throw; } }