public IHttpActionResult SaveAccountBook(AcctBookViewModels acctBook) { string err; if (!_modelValid.ValidAccountBookCreate(acctBook, out err)) { ResMessage.Fail(err); } _acctBook.Save(acctBook); return(Ok(ResMessage.Success())); }
public AccountBook Save(AcctBookViewModels acctBook) { AccountBook book = null; bool isNew = false; if (string.IsNullOrEmpty(acctBook.AbId)) { book = new AccountBook(); book.AbId = Guid.NewGuid(); book.Currency = acctBook.Currency; book.StartYear = acctBook.StartYear; book.StartPeriod = acctBook.StartPeriod; book.FiscalSystem = (FiscalSystem)acctBook.FiscalSystem; book.State = AccountBookState.Normal; book.Company = new Company(); book.Company.ComName = acctBook.ComapnyName; //默认新公司都是南宁的 book.Company.Region = _ledger.Regions.Where(r => r.RegionCode == 450100).FirstOrDefault(); book.Creator = _identity.GetUserName(); book.CreateTime = DateTime.Now; //创建人默认具有编辑账套内容的权限 UserBook ub = new UserBook(); ub.AccountBook = book; ub.UserId = _identity.GetUserId(); book.Users.Add(ub); _ledger.AccountBooks.Add(book); isNew = true; } else { book = _ledger.AccountBooks.Where(ab => ab.AbId == Guid.Parse(acctBook.AbId)).FirstOrDefault(); book.Currency = acctBook.Currency; book.FiscalSystem = (FiscalSystem)acctBook.FiscalSystem; isNew = false; } if (_ledger.SaveChanges() > 0 && isNew) { //初始化数据 this.AccountBookInitData(book.AbId); } return(book); }
public bool ValidAccountBookCreate(AcctBookViewModels acctBook, out string err) { err = ""; if (_company.GetCompanyByName(acctBook.ComapnyName) != null) { err = "公司名称已存在"; } bool res = string.IsNullOrEmpty(err); if (!res) { _log.Warn(err); } return(res); }