public void UsingLinqFromNonLinqBaseClass() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); Widget widget0 = new Widget { Name = "Hello world" }; widget0.Save(); using (new SessionScope()) { var widgets = from w in ActiveRecordLinq.AsQueryable <Widget>() select w; Assert.IsNotNull(widgets); Assert.AreEqual(1, widgets.Count()); var widget = (from w in ActiveRecordLinq.AsQueryable <Widget>() select w).First(); Assert.IsNotNull(widget); Assert.AreEqual("Hello world", widget.Name); var widget2 = ActiveRecordLinq.AsQueryable <Widget>().First(w => w.Name == "Hello World"); Assert.IsNotNull(widget2); Assert.AreEqual("Hello world", widget2.Name); Assert.AreSame(widget2, widget); } }
public void Process() { using (new SessionScope(FlushAction.Never)) { var payers = ActiveRecordLinq.AsQueryable <Payer>() .Where(p => p.SendPaymentNotification && p.Balance < 0) .ToList(); var usersForNotification = payers.SelectMany(p => p.Users) .Where(u => u.Client != null && u.Enabled && u.Client.Enabled && !u.Accounting.IsFree); foreach (var user in usersForNotification) { Cacellation.ThrowIfCancellationRequested(); var message = UserMessage.Find(user.Id); message.ShowMessageCount = 1; if (IsFirstNotification()) { message.Message = FirstNotificationText; } else { message.Message = SecondNotificationText; } using (var scope = new TransactionScope(OnDispose.Rollback)) { message.Save(); scope.VoteCommit(); } } } }
public static IEnumerable <Payment> Identify(IEnumerable <Payment> payments) { var recipients = ActiveRecordLinqBase <Recipient> .Queryable.ToList(); var ignoredInns = IgnoredInn.Queryable.ToList(); foreach (var payment in payments) { payment.Recipient = recipients.FirstOrDefault(r => r.BankAccountNumber == payment.RecipientClient.AccountCode); if (payment.Recipient == null) { continue; } var inn = payment.PayerClient.Inn; if (!ignoredInns.Any(i => String.Equals(i.Name, inn, StringComparison.InvariantCultureIgnoreCase))) { var payer = ActiveRecordLinq.AsQueryable <Payer>().FirstOrDefault(p => p.INN == inn); payment.Payer = payer; } if (payment.IsDuplicate()) { continue; } yield return(payment); } }
public string GetWarning() { if (Payer != null || PayerClient == null) { return(""); } var payers = ActiveRecordLinq.AsQueryable <Payer>().Where(p => p.INN == PayerClient.Inn).ToList(); if (payers.Count == 0) { return(String.Format("Не удалось найти ни одного плательщика с ИНН {0}", PayerClient.Inn)); } else if (payers.Count == 1) { Payer = payers.Single(); return(""); } else { return(String.Format("Найдено более одного плательщика с ИНН {0}, плательщики с таким ИНН {1}", PayerClient.Inn, payers.Implode(p => p.Name))); } }
public void Linq_without_session_scope_should_fail() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); ActiveRecordLinq.AsQueryable <Widget>(); }
public void Linq_without_session_scope() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Widget)); Recreate(); Widget.DeleteAll(); var widgets = from w in ActiveRecordLinq.AsQueryable <Widget>() select w; Assert.IsNotNull(widgets); Assert.AreEqual(0, widgets.Count()); }
public object SearchCatalog(string term) { return(ActiveRecordLinq .AsQueryable <Catalog>() .Where(c => !c.Hidden && c.Name.Contains(term)) .Take(20) .ToList() .Select(c => new { id = c.Id, label = c.Name })); }
public object SearchPayer(string term) { uint id; uint.TryParse(term, out id); return(ActiveRecordLinq .AsQueryable <Payer>() .Where(p => p.Name.Contains(term) || p.Id == id) .Take(20) .ToList() .Select(p => new { id = p.Id, label = String.Format("[{0}]. {1} ИНН {2}", p.Id, p.Name, p.INN), recipient = p.Recipient != null ? p.Recipient.Id : 0 })); }
public static Administrator GetByName(string name) { //удаляем имя домена, например было analit\kvasov стало kvasov if (name.IndexOf(@"\") > 0) { name = name.Split(new[] { @"\" }, StringSplitOptions.RemoveEmptyEntries).Last(); } var admin = ActiveRecordLinq.AsQueryable <Administrator>().FirstOrDefault(a => a.UserName == name); if (admin != null) { NHibernateUtil.Initialize(admin.AllowedPermissions); } return(admin); }
protected override void Process() { var timeToSendMail = ConfigurationManager.AppSettings["SendPremoderatedPomotionListAt"] .Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); var timeToSendMailHour = int.Parse(timeToSendMail[0]); var timeToSendMailMinutes = timeToSendMail.Length > 1 ? int.Parse(timeToSendMail[1]) : 0; var mailTime = SystemTime.Now().Date.AddHours(timeToSendMailHour).AddMinutes(timeToSendMailMinutes); if (SystemTime.Now() >= mailTime && SystemTime.Now() < mailTime.AddMinutes(30)) { using (new SessionScope(FlushAction.Never)) { var promotions = ActiveRecordLinq.AsQueryable <SupplierPromotion>() .Where(p => !p.Moderated && p.Enabled && p.Moderator == null).OrderBy(s => s.Begin).ToList(); if (promotions.Count > 0) { _mailer = (_mailer ?? new MonorailMailer()).PremoderatedPromotions(promotions); _mailer.Send(); } } } }