protected override NgResult _update(EmailSenderDataProviderVM[] models)
 {
     using (var l = new MessagesModuleLogic()) {
         foreach (var model in models)
         {
             var item = l.Get <tblEmailSenderDataProvider>(model.Id);
             EmailSenderDataProviderVM.ReflectToTblEmailSenderDataProvider.Run(model, item);
             l.SaveChanges(item);
         }
     }
     return(NgResult.Succes(DEBS.Translate("MessageMdl.{0} email providers was modified", models.Count())));
 }
Ejemplo n.º 2
0
 protected override NgResult _update(MessageScheduleVM[] models)
 {
     using (var l = new MessagesModuleLogic()) {
         foreach (var model in models)
         {
             var item = l.Get <tblMessageSchedule>(model.Id);
             MessageScheduleVM.ReflectToTblMessageSchedule.Run(model, item);
             l.SaveChanges(item);
         }
     }
     return(NgResult.Succes(DEBS.Translate("MessageMdl.{0} schedules was modified", models.Count())));
 }
Ejemplo n.º 3
0
        public static void RunScheduledBatchSending(MessagesModuleLogic Logic, BatchSendingTaskSettings Settings = null)
        {
            if (!ScheduledBatchSending_H.GetSafeThreadPermission())
            {
                return;
            }
            try {
                Settings = Settings ?? DefaultsBatchSendingTaskSettings;
                using (var manager = BatchSendingManager.NewInstance(Settings, Logic)) {
                    var allPendingMails = manager.GetPendingEmails();
                    var allPendingSms   = manager.GetPendingSms();

                    var batches = allPendingMails
                                  .Select(x => x.tblMessageBatch)
                                  .Distinct()
                                  .Concat(allPendingSms
                                          .Select(x => x.tblMessageBatch)
                                          .Distinct())
                                  .ToArray();

                    //EMAIL
                    var emailProviders = manager.GetActiveEmailProviders().ToList().GetEnumerator();
                    var Emailer        = new EmailSender(manager);
                    SendCycle(manager, allPendingMails, emailProviders, Emailer);
                    //SMS
                    var smsProviders = manager.GetActiveSmsProviders().ToList().GetEnumerator();
                    var Smser        = new SmsSender(manager);
                    SendCycle(manager, allPendingSms, smsProviders, Smser);

                    foreach (var batch in batches)
                    {
                        //check if batch finished
                        if (!batch.tblMessages.Where(x => (x.tblPendingMessagesQueue != null) && (!x.tblPendingMessagesQueue.Deleted)).Any())
                        {
                            batch.FinishedOn = DateTime.Now;
                        }
                        //TODO THIS CHECK IS NOT RIGHT DECISION
                        //add errors to batch if there are some
                        if (batch.tblMessages.Where(x => x.ErrorLog != null).Any())
                        {
                            (batch as IErrorLoged).AddError("Some errors have arisen at sending stage at " + DateTime.Now.ToShortDateString());
                        }
                        manager.Logic.SaveLazy(batch);
                    }
                    Logic.SaveChanges();
                    //Logic.Dispose();
                }
            }
            finally {
                ScheduledBatchSending_H.ReportTaskEnded();
            }
        }
 protected override NgResult _update(RFilterVM[] models)
 {
     using (var l = new MessagesModuleLogic()) {
         foreach (var model in models)
         {
             var filt = l.Get <tblRecepientFilter>(model.Id);
             filt.Name = model.Name;
             filt.tblRecepientFilterTableNameId = model.BaseTableId;
             l.SaveChanges(filt);
             model.Id = filt.Id;
             CreateAndUpdateRFilterParts(model, l);
         }
     }
     return(NgResult.Succes());
 }
 protected void ManagerRFilterPart <TEnitity, TNgViewModel> (MessagesModuleLogic l, IEnumerable <TNgViewModel> items, Action <TEnitity, TNgViewModel> updater)
     where TEnitity : class, IMessagesModuleEntity
     where TNgViewModel : class, INgViewModel
 {
     if (items == null)
     {
         return;
     }
     //TODO OPTIMIZE work with DB
     foreach (var item in items)
     {
         TEnitity ent = null;
         if (item.ng_ToDelete)
         {
             l.Delete <TEnitity>(item.Id);
         }
         else if (item.ng_JustCreated)
         {
             ent = l.Create <TEnitity>();
         }
         else
         {
             ent = l.Get <TEnitity>(item.Id);
         }
         if (ent != null)
         {
             updater(ent, item);
             if (item.ng_JustCreated)
             {
                 l.Add(ent);
             }
             else
             {
                 l.SaveChanges(ent);
             }
         }
     }
 }