public int Save(CertWordViewModel certWord) { if (certWord.CwId > 0) { CertificateWord cw = _ledger.CertificateWords.Where(c => c.CwId == certWord.CwId).FirstOrDefault(); if (cw != null) { cw.CertWord = certWord.CertWord; cw.PrintTitle = certWord.PrintTitle; if (certWord.IsDefault) { this.SetDefault(cw.CwId); } } } else { CertificateWord newWord = new CertificateWord(); newWord.CertWord = certWord.CertWord; newWord.PrintTitle = certWord.PrintTitle; newWord.IsDefault = false; Guid abid = _cache.GetUserCache().AccountBookID; newWord.AccountBook = _ledger.AccountBooks.Where(ab => ab.AbId == abid).FirstOrDefault(); _ledger.CertificateWords.Add(newWord); } return(_ledger.SaveChanges()); }
public int Delete(int certWordId) { CertificateWord cWord = _ledger.CertificateWords.Where(cw => cw.CwId == certWordId).FirstOrDefault(); if (cWord != null) { _ledger.CertificateWords.Remove(cWord); return(_ledger.SaveChanges()); } return(0); }
public int SetDefault(int certWordId) { CertificateWord cWord = _ledger.CertificateWords.Where(cw => cw.CwId == certWordId).FirstOrDefault(); List <CertificateWord> certWords = this.GetCertWordInAccountBook(); if (cWord != null) { var defWord = certWords.Where(cw => cw.IsDefault).FirstOrDefault(); if (defWord != null) { defWord.IsDefault = false; } cWord.IsDefault = true; return(_ledger.SaveChanges());; } return(0); }
private void AccountBookInitData(Guid newAbId) { //添加初始科目 Guid abid = new Guid("00000000-0000-0000-0000-000000000000"); List <Account> baseAccounts = _ledger.Accounts.Where(a => a.AbId == abid).ToList(); foreach (Account acc in baseAccounts) { Account newAccount = new Account(); newAccount.AccCode = acc.AccCode; newAccount.ParentAccCode = acc.ParentAccCode; newAccount.AcId = acc.AcId; newAccount.AccName = acc.AccName; newAccount.Direction = acc.Direction; newAccount.IsAuxiliary = false; newAccount.IsQuantity = false; newAccount.State = AccountState.Normal; newAccount.AbId = newAbId; newAccount.Creator = _identity.GetUserName(); newAccount.CreateTime = DateTime.Now; _ledger.Accounts.Add(newAccount); } //添加初始凭证字 CertificateWord defCertWord = new CertificateWord(); defCertWord.CertWord = "记"; defCertWord.PrintTitle = "记"; defCertWord.AbId = newAbId; defCertWord.IsDefault = true; _ledger.CertificateWords.Add(defCertWord); //保存初始数据 _ledger.SaveChanges(); }