本文整理汇总了C#中IUnitOfWork.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# IUnitOfWork.Commit方法的具体用法?C# IUnitOfWork.Commit怎么用?C# IUnitOfWork.Commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUnitOfWork
的用法示例。
在下文中一共展示了IUnitOfWork.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TokenService
public TokenService(IHashProvider hashProvider, IUnitOfWork unitOfWork)
{
_hashProvider = hashProvider;
_tokenRespository = unitOfWork.GetRepository<ITokenRepository>();
_tokenRespository.OnAdd += (sender, args) => unitOfWork.Commit();
_tokenRespository.OnDelete += (sender, args) => unitOfWork.Commit();
}
示例2: releaseTheTable
public static void releaseTheTable(string type, object key, IUnitOfWork uow)
{
lock (_syncObj_cache)
{
string key4Trans = getKey(type, key);
if (_cache.ContainsKey(key4Trans))
{
var info = (SqlTransactionManagerInfo)_cache[key4Trans];
if (info != null)
{
SqlTransactionManager.SetCurrentSqlTransactionManagerInfo(info);
try
{
uow.Commit();
SqlTransactionManager.Commit();
}
catch (Exception e)
{
SqlTransactionManager.Rollback();
throw e;
}
finally
{
SqlTransactionManager.Dispose();
SqlTransactionManager.End();
}
}
}
}
}
示例3: object
private static object _syncObj_cache = new object();//Is there a bottleneck of this lock?
#endregion
public static void lockTheTable(string type, object key, IUnitOfWork uow)
{
lock (_syncObj_cache)
{
string key4Trans = getKey(type, key);
if (!_cache.ContainsKey(key4Trans))
{
SqlTransactionManager.Begin();
uow.Commit();
_cache.Add(key4Trans, SqlTransactionManager.GetCurrentSqlTransactionManagerInfo());
}
}
}
示例4: Add
public void Add()
{
try
{
_unitOfWork = new UnitOfWork();
IUserRepository userRepository = new UserUnitOfWorkRepository(_unitOfWork);
if (userRepository.GetByKey(_id) == null)
{
userRepository.Add(new User() { Id = _id, Duty = "管理员", Name = "hy", Email = "bbs", RoleId = "SuperManager",Password="hy" });
}
_unitOfWork.Commit();
}
catch (Exception ex)
{
Assert.IsTrue(false);
}
}
示例5: Add
public void Add()
{
try
{
_unitOfWork = new UnitOfWork();
IAuthorityRepository authorityRepository = new AuthorityUnitOfWorkRepository(_unitOfWork);
List<Authority> list = authorityRepository.GetAll().ToList();
if (list == null) list = new List<Authority>();
if (list.Where(it => it.Id.Equals("Login")).FirstOrDefault() == null)
{
authorityRepository.Add(new Authority() { Id = "Login", Name = "登录" });
}
if (list.Where(it => it.Id.Equals("Register")).FirstOrDefault() == null)
{
authorityRepository.Add(new Authority() { Id = "Register", Name = "注册" });
}
_unitOfWork.Commit();
}
catch (Exception ex)
{
Assert.IsTrue(false);
}
}
示例6: Add
public void Add()
{
try
{
_unitOfWork = new UnitOfWork();
IAuthorizeRepository authorizeRepository = new AuthorizeUnitOfWorkRepository(_unitOfWork);
List<Authorize> list = authorizeRepository.GetAll().ToList();
if (list == null) list = new List<Authorize>();
if (list.Where(it => it.AuthorityName.Equals("Login")).FirstOrDefault() == null)
{
authorizeRepository.Add(new Authorize() { AuthorityName = "Login", RoleName = "SuperManager,RegisterUser" });
}
if (list.Where(it => it.AuthorityName.Equals("Register")).FirstOrDefault() == null)
{
authorizeRepository.Add(new Authorize() { AuthorityName = "Register", RoleName = "SuperManager,RegisterUser" });
}
_unitOfWork.Commit();
}
catch (Exception ex)
{
Assert.IsTrue(false);
}
}
示例7: GetAll
public void GetAll()
{
_unitOfWork = new UnitOfWork();
IAuthorizeRepository authorizeRepository = new AuthorizeUnitOfWorkRepository(_unitOfWork);
List<Authorize> list = authorizeRepository.GetAll().ToList();
Assert.IsTrue(list != null && list.Count > 0);
_unitOfWork.Commit();
}
示例8: Del
public void Del()
{
_unitOfWork = new UnitOfWork();
IAuthorizeRepository authorizeRepository = new AuthorizeUnitOfWorkRepository(_unitOfWork);
authorizeRepository.Del(new Authorize() { AuthorityName = "Login", RoleName = "SuperManager" });
_unitOfWork.Commit();
}
示例9: GetByKey
public void GetByKey()
{
_unitOfWork = new UnitOfWork();
IAuthorizeRepository authorizeRepository = new AuthorizeUnitOfWorkRepository(_unitOfWork);
Authorize authorize = authorizeRepository.GetByKey("Login");
Assert.AreEqual<Authorize>(new Authorize() { AuthorityName = "Login", RoleName = "SuperManager,RegisterUser" }, authorize);
_unitOfWork.Commit();
}
示例10: Del
public void Del()
{
try
{
_unitOfWork = new UnitOfWork();
IUserRepository userRepository = new UserUnitOfWorkRepository(_unitOfWork);
userRepository.Del(new User() { Id = _id });
_unitOfWork.Commit();
}
catch (Exception ex)
{
Assert.IsTrue(false);
}
}
示例11: Save
public void Save()
{
try
{
_unitOfWork = new UnitOfWork();
IUserRepository userRepository = new UserUnitOfWorkRepository(_unitOfWork);
User user = userRepository.GetByKey(_id);
user.Name = "polan";
userRepository.Save(user);
_unitOfWork.Commit();
}
catch (Exception ex)
{
Assert.IsTrue(false);
}
}
示例12: ProcessExcelSheet
//.........这里部分代码省略.........
objXmlWriter3.WriteStartElement("GSTCLASS"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteElementString("ISDEEMEDPOSITIVE", "No");
objXmlWriter3.WriteElementString("LEDGERFROMITEM", "No"); objXmlWriter3.WriteElementString("REMOVEZEROENTRIES", "No");
objXmlWriter3.WriteElementString("ISPARTYLEDGER", "No"); objXmlWriter3.WriteElementString("ISLASTDEEMEDPOSITIVE", "No");
objXmlWriter3.WriteElementString("AMOUNT", itemsTotalAmt.ToString()); objXmlWriter3.WriteStartElement("BANKALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("BILLALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("INTERESTCOLLECTION.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("OLDAUDITENTRIES.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("ACCOUNTAUDITENTRIES.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("AUDITENTRIES.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("TAXBILLALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("TAXOBJECTALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("TDSEXPENSEALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("VATSTATUTORYDETAILS.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("COSTTRACKALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("OLDAUDITENTRIES.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("ACCOUNTAUDITENTRIES.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("TAXOBJECTALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteStartElement("EXCISEALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteStartElement("EXPENSEALLOCATIONS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteEndElement();
q++;
itemNetAmt = XcelServiceHelper.TruncateDecimal(itemNetAmt, 2);
decimal chkItemTax = con.ConsultantPrice - (itemNetAmt + itemTax);
if (chkItemTax <= 1 || chkItemTax >= -1)
{
itemTax = itemTax + chkItemTax;
}
PostedTransaction trans;
trans = unitOfWork.PostedTransactions.All()
.Where(x => x.ItemCode == con.ItemCode)
.Where(x => x.OrderId == con.OrderId)
.Where(x => x.ConsultantCode == con.Consultant.ConsultantId)
.FirstOrDefault();
if (trans == null)
{
trans = new PostedTransaction
{
Company = model.Company,
UnitName = unit.Unit,
AssemblyName = assembly,
ConsultantName = uCon.Consultant,
ConsultantCode = uCon.ConsultantId,
PostDate = DateTime.Now,
Year = year,
Week = week,
InvoiceNo = VoucherNo,
GrossAmount = con.Amount,
ConsultantPrice = con.ConsultantPrice,
NetAmount = itemNetAmt,
VatAmount = itemTax,
ItemCode = con.ItemCode,
ItemName = con.ItemName,
OrderId = con.OrderId,
OrderQty = con.OrdQty,
Status = con.Status,
PayStatus = enPaymentStatus.Pending,
InventoryStatus = enInventoryStatus.Pending,
PaymentAmount = 0,
PostType = enPostType.Invoice_12_5_WithAddress
};
unitOfWork.PostedTransactions.Insert(trans);
}
else
{
trans.ItemCode = con.ItemCode;
trans.GrossAmount = con.Amount;
trans.ConsultantPrice = con.ConsultantPrice;
trans.NetAmount = itemNetAmt;
trans.VatAmount = itemTax + (con.ConsultantPrice - (itemNetAmt + itemTax));
trans.ItemCode = con.ItemCode;
trans.ItemName = con.ItemName;
trans.OrderId = con.OrderId;
trans.OrderQty = con.OrdQty;
trans.Status = con.Status;
unitOfWork.PostedTransactions.Update(trans);
}
}
}
#endregion VAT_5%
objXmlWriter3.WriteStartElement("ATTDRECORDS.LIST"); objXmlWriter3.WriteEndElement();
objXmlWriter3.WriteEndElement(); objXmlWriter3.WriteEndElement();
//strData = strData + "<ATTDRECORDS.LIST> </ATTDRECORDS.LIST>" +
//"</VOUCHER></TALLYMESSAGE>";
objXmlWriter3.Flush();
}
//objXmlWriter3.Dispose();
}
unitOfWork.Commit();
unitOfWork.Dispose();
}
string closeTag = "</REQUESTDATA></IMPORTDATA></BODY></ENVELOPE>";
var fs = System.IO.File.Open(savePath + "//payment.xml", System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite);
fs.Position = fs.Length;
var writer = new StreamWriter(fs); // after the Position is set
writer.Write(closeTag); // NOT WriteLine !!
writer.Close();
fs.Close();
}
}
示例13: CreateAndCommitMultipleUsers
private IUser[] CreateAndCommitMultipleUsers(IUserRepository repository, IUnitOfWork unitOfWork)
{
var user1 = MockedUser.CreateUser(CreateAndCommitUserType(), "1");
var user2 = MockedUser.CreateUser(CreateAndCommitUserType(), "2");
var user3 = MockedUser.CreateUser(CreateAndCommitUserType(), "3");
repository.AddOrUpdate(user1);
repository.AddOrUpdate(user2);
repository.AddOrUpdate(user3);
unitOfWork.Commit();
return new IUser[] { user1, user2, user3 };
}
示例14: NotifyNewTopics
private void NotifyNewTopics(Category cat, Topic topic, IUnitOfWork unitOfWork)
{
var settings = SettingsService.GetSettings();
// Get all notifications for this category and for the tags on the topic
var notifications = _categoryNotificationService.GetByCategory(cat).Select(x => x.User.Id).ToList();
// Merge and remove duplicate ids
if (topic.Tags != null && topic.Tags.Any())
{
var tagNotifications = _tagNotificationService.GetByTag(topic.Tags.ToList()).Select(x => x.User.Id).ToList();
notifications = notifications.Union(tagNotifications).ToList();
}
if (notifications.Any())
{
// remove the current user from the notification, don't want to notify yourself that you
// have just made a topic!
notifications.Remove(LoggedOnReadOnlyUser.Id);
if (notifications.Count > 0)
{
// Now get all the users that need notifying
var usersToNotify = MembershipService.GetUsersById(notifications);
// Create the email
var sb = new StringBuilder();
sb.AppendFormat("<p>{0}</p>", string.Format(LocalizationService.GetResourceString("Topic.Notification.NewTopics"), cat.Name));
sb.Append($"<p>{topic.Name}</p>");
if (SiteConstants.Instance.IncludeFullPostInEmailNotifications)
{
sb.Append(AppHelpers.ConvertPostContent(topic.LastPost.PostContent));
}
sb.AppendFormat("<p><a href=\"{0}\">{0}</a></p>", string.Concat(Domain, cat.NiceUrl));
// create the emails and only send them to people who have not had notifications disabled
var emails = usersToNotify.Where(x => x.DisableEmailNotifications != true && !x.IsLockedOut && x.IsBanned != true).Select(user => new Email
{
Body = _emailService.EmailTemplate(user.UserName, sb.ToString()),
EmailTo = user.Email,
NameTo = user.UserName,
Subject = string.Concat(LocalizationService.GetResourceString("Topic.Notification.Subject"), settings.ForumName)
}).ToList();
// and now pass the emails in to be sent
_emailService.SendMail(emails);
try
{
unitOfWork.Commit();
}
catch (Exception ex)
{
unitOfWork.Rollback();
LoggingService.Error(ex);
}
}
}
}
示例15: GetByKey
public void GetByKey()
{
_unitOfWork = new UnitOfWork();
IAuthorityRepository authorityRepository = new AuthorityUnitOfWorkRepository(_unitOfWork);
Authority authority= authorityRepository.GetByKey("Login");
Assert.AreEqual<Authority>(new Authority() { Id = "Login", Name = "登录" }, authority);
_unitOfWork.Commit();
}