public void UpdateFirstBalance(BalanceJournalViewModel parent, List <BalanceJournalDetailViewModel> details, int userId) { BalanceJournal entity = _balanceJournalRepository.GetById(parent.Id); Map(parent, entity); entity.ModifyUserId = userId; entity.ModifyDate = DateTime.Now; _balanceJournalRepository.AttachNavigation <User>(entity.CreateUser); _balanceJournalRepository.AttachNavigation <User>(entity.ModifyUser); _balanceJournalRepository.Update(entity); _unitOfWork.SaveChanges(); foreach (var balanceDetail in details) { if (balanceDetail.Id > 0) { BalanceJournalDetail detailEntity = _balanceJournalDetailRepository.GetById(balanceDetail.Id); Map(balanceDetail, detailEntity); _balanceJournalDetailRepository.AttachNavigation <BalanceJournal>(detailEntity.Parent); _balanceJournalDetailRepository.AttachNavigation <JournalMaster>(detailEntity.Journal); _balanceJournalDetailRepository.Update(detailEntity); } else { BalanceJournalDetail detailEntity = new BalanceJournalDetail(); Map(balanceDetail, detailEntity); detailEntity.ParentId = entity.Id; _balanceJournalDetailRepository.AttachNavigation <BalanceJournal>(detailEntity.Parent); _balanceJournalDetailRepository.AttachNavigation <JournalMaster>(detailEntity.Journal); _balanceJournalDetailRepository.Add(detailEntity); } } _unitOfWork.SaveChanges(); }
public void DeleteBalanceJournal(int headerId, int userId) { BalanceJournal entity = _balanceJournalRepository.GetById(headerId); entity.Status = (int)DbConstant.DefaultDataStatus.Deleted; entity.ModifyDate = DateTime.Now; entity.ModifyUserId = userId; _balanceJournalRepository.AttachNavigation <User>(entity.CreateUser); _balanceJournalRepository.AttachNavigation <User>(entity.ModifyUser); _balanceJournalRepository.Update(entity); _unitOfWork.SaveChanges(); }