public static async Task Send(Db db)
		{
			var host = HttpContext.Current?.Request.ServerVariables["HTTP_HOST"];
            if (host == null || !host.Equals("jeegoordah.azurewebsites.net", StringComparison.InvariantCultureIgnoreCase))
			{
				throw new Exception($"Sending notifications is disabled for {host}");
			}

			var sendTasks = db.Query<Bro>()
				.Where(x => x.Email != null)
				.Where(x => x.Notifications.Count > 0)
				.ToArray()
				.Select(async bro =>
				{
					var message = new SendGridMessage
					{
						From = _from,
						To = new[] {new MailAddress(bro.Email)},
						Subject = "Jeegoordah notifications",
						Text = GetContent(bro.Notifications),
						Html = null,
					};

					_logger.I($"Sending {bro.Notifications.Count} notifications for {bro.Name}");
					await _transport.DeliverAsync(message);
					_logger.I($"Notifications for {bro.Name} sent");
				});

			await Task.WhenAll(sendTasks);

			db.Query<Notification>().ForEach(db.Session.Delete);
			_logger.I("Notifications deleted");
		}
예제 #2
0
파일: Program.cs 프로젝트: jeroldhaas/Soma
        private static void Main(string[] args)
        {
            var db = new Db(new MyConfig());

            for (int i = 0; i < 500; i++)
            {
                db.Query<Employee>("select * from Employee where EmployeeId = /*id*/0", new {id = 1});
            }
            Console.WriteLine("Done");
        }
예제 #3
0
파일: Program.cs 프로젝트: jeroldhaas/Soma
        private static void Main()
        {
            var db = new Db(new MyConfig());

            // execute following code in a transaction, but don't commit
            using (new TransactionScope())
            {
                // find by id
                var emp = db.Find<Employee>(1);
                Console.WriteLine("FOUND ENTITY : \n{0}\n", emp);

                // update
                emp.EmployeeName = "Hoge";
                db.Update(emp);
                Console.WriteLine("UPDATED ENTITY : \n{0}\n", emp);

                // delete
                db.Delete(emp);
                Console.WriteLine("DELETED ENTITY : \n{0}\n", emp);

                // insert
                emp = new Employee { EmployeeName = "Allen", DepartmentId = 2 };
                db.Insert(emp);
                Console.WriteLine("INSERTED ENTITY : \n{0}\n", emp);

                // query and map results to entities. parameters are bindable with "Anonymous Types".
                var empList = db.Query<Employee>(@"
                    select
                        e.EmployeeId,
                        e.EmployeeName,
                        e.DepartmentId,
                        e.VersionNo
                    from
                        Employee e
                    where
                        e.DepartmentId = /* emp.DepartmentId */0
                    ", new { emp });
                Console.WriteLine("QUERRY RESULTS AS ENTITIES :");
                foreach (var e in empList)
                {
                    Console.WriteLine(e);
                }
                Console.WriteLine();

                // query and map results to dynamic objects. parameters are bindable with "Anonymous Types".
                var empList2 = db.Query<dynamic>(@"
                    select
                        e.EmployeeId,
                        e.EmployeeName,
                        e.DepartmentId,
                        e.VersionNo
                    from
                        Employee e
                    where
                        e.DepartmentId = /* emp.DepartmentId */0
                    ", new { emp });
                Console.WriteLine("QUERY RESULTS AS DYNAMIC OBJECTS :");
                foreach (var e in empList2)
                {
                    Console.WriteLine("EmployeeId={0}, EmployeeName={1}", e.EmployeeId, e.EmployeeName);
                }
                Console.WriteLine();

                // call procedure
                var procedure = new ProcResultAndOut { EmployeeId = 1 };
                db.Call(procedure);
                Console.WriteLine("PROCEDURE OUTPUT VALUE : \n{0}\n", procedure.EmployeeCount);
                Console.WriteLine("PROCEDURE RESULT ENTITIES :");
                foreach (var e in procedure.Employees)
                {
                    Console.WriteLine(e);
                }
                Console.WriteLine();

                // execute arbitrary SQL
                var rows = db.Execute("delete from Employee");
                Console.WriteLine("AFFECTED ROWS : \n{0}\n", rows);
            }
            Console.ReadKey();
        }
예제 #4
0
        private bool AssertNameUnique(EventRest @event, Db db, out JsonResult result)
        {
            result = null;
            bool conflict = @event.Id.HasValue
                ? db.Query<Event>().Any(e => e.Id != @event.Id.Value && e.Name == @event.Name)
                : db.Query<Event>().Any(e => e.Name == @event.Name);
            if (!conflict) return true;

            Logger.E("Attempt to create duplicate event {0}", @event.Name);
            result = Json(new {Field = "Name", Message = "Event with name {0} already exists.".F(@event.Name)});
            Response.StatusCode = 400;
            return false;
        }
        private ExchangeRatesUpdater(Db db)
        {
            this.db = db;
	        byn = db.Query<Currency>().Where(c => c.Name == "BYN").First();
        }