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 IHttpActionResult SaveCertWord(CertWordViewModel certWord) { _certWord.Save(certWord); return(Ok(ResMessage.Success())); }