Пример #1
0
        public IEnumerable <JobInfo> FindRelevantJobs(int[] skillsId, string keyWords, int priceFrom, int[] emloyeeSkillsId = null)
        {
            Expression <Func <Job, bool> > filter = JobFilter(skillsId, keyWords, priceFrom);

            const int skillsPercent = 40;
            const int pricePercent  = 30;
            const int datePercent   = 20;
            const int viewsPercent  = 10;

            const double maxPrice = 100000;
            const double maxViews = 100000;
            const double maxHours = 4320; //180 days

            var jobSkills = skillsId == null?Enumerable.Empty <int>() : skillsId;

            var employeeSkills = emloyeeSkillsId == null?Enumerable.Empty <int>() : emloyeeSkillsId;

            var    skillsForSort         = jobSkills.Union(employeeSkills);
            double maxSkillsCountForSort = skillsForSort.Count() == 0 ? 1 : skillsForSort.Count();

            Expression <Func <JobInfo, double> > sortByRelevant = (j) =>
                                                                  (j.Skills.Count(s => skillsForSort.Contains(s.Id)) / maxSkillsCountForSort * skillsPercent) +
                                                                  (j.Price / maxPrice * pricePercent) +
                                                                  (j.CountViews / maxViews * viewsPercent) -
                                                                  ((double)DbFunctions.DiffHours(j.DateAdded, DateTime.UtcNow) / maxHours * datePercent);


            return(_jobRepository.FindJobsInfo(filter)
                   .OrderByDescending(sortByRelevant)
                   .ToList());
        }
Пример #2
0
        public async Task <bool> UpdateAppointment(AppointmenTO filtro)
        {
            List <AppointmenTO> appointmentsByPacient = new List <AppointmenTO>();

            using (AppointmentsEntities dbContext = new AppointmentsEntities())
            {
                appointmentsByPacient = await(from app in dbContext.Appointments
                                              join pat in dbContext.Pacients on app.IdKeyPacient equals pat.IdKey
                                              where app.IdKeyPacient == filtro.IdKeyPacient &&
                                              app.IdKey == filtro.IdKey &&
                                              DbFunctions.DiffHours(app.Date, SqlFunctions.GetDate().Value) <= 24
                                              select app).ProjectTo <AppointmenTO>().ToListAsync();

                if (appointmentsByPacient.Count <= 0)
                {
                    Appointment AppointmentUpdate = Mapper.Map <Appointment>(filtro);
                    dbContext.Appointments.Attach(AppointmentUpdate);
                    var entry = dbContext.Entry(AppointmentUpdate);
                    entry.Property(e => e.IdState).IsModified = true;
                    // other changed properties
                    dbContext.SaveChanges();
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        public IQueryable <IPs> ScannableIpsQ()
        {
            Update();
            var now = DateTime.Now;

            return(from ip in model.IPs
                   where ip.LastAttack != null && DbFunctions.DiffHours(now, ip.LastAttack) > 1
                   //where now.Hour - ip.LastAttack.Hour > 1
                   select ip);



            //return GetIps()
            //        .Where(ip =>
            //        {
            //            return (now - ip.LastAttack) > TimeSpan.FromHours(1);

            //            //if (ip.Attacks == null || ip.Attacks.Count == 0)
            //            //    return true; // not yet attacked

            //            //var lastAttack = ip.Attacks
            //            //    .Select(att => att.Dt)
            //            //    .OrderByDescending(dt => dt)
            //            //    .FirstOrDefault();

            //            //return (now - lastAttack) > TimeSpan.FromHours(1);
            //        });
        }
Пример #4
0
        private static LinkedList <Trip> readDb(DateTime departureTime, int type)
        {
            LinkedList <Trip> list = new LinkedList <Trip>();
            CarpoolContext    db   = new CarpoolContext();
            var trips = from trip in db.Trips
                        where
                        DbFunctions.DiffHours(trip.TravelDateTime, departureTime) < 6 &&
                        departureTime > trip.TravelDateTime &&
                        trip.TripInformation.Capacity >= 1 &&
                        ((int)trip.Type == (type == 0?1:0))
                        select trip;

            foreach (var a in trips)
            {
                Location from = new Location(a.From.StreetAddress, a.From.City, a.From.State, a.From.ZipCode);
                Location to   = new Location(a.To.StreetAddress, a.To.City, a.To.State, a.To.ZipCode);
                DateTime time = a.TravelDateTime;
                Trip     trip = new Trip(from, to, time, a.Type, a.TripInformation);
                list.AddFirst(trip);
            }
            return(list);



            // string[] lines = System.IO.File.ReadAllLines(@"C:\Users\sgpy\Documents\GitHub\carpool-master\CarPoolDemo\db.txt");

            //  foreach (string line in lines)
            // {
            //      string[] item = line.Split('\t');
            //      Trip trip = new Trip(item[0].Trim(), item[1].Trim(), item[2].Trim(), item[3].Trim(), item[4].Trim(), item[5].Trim());
            //      list.AddFirst(trip);
            //  }
            // return list;
        }
Пример #5
0
        public ActionResult Index()
        {
            // Retrieve users
            // Note: Hirer accounts use email addresses as username, so the list filters out usernames that are email addresses
            // This display is only to modify internal Machete user accounts (not to modify employer accounts)
            IDbSet <MacheteUser> users = DatabaseFactory.Get().Users;

            if (users == null)
            {
                // TODO: throw alert
            }
            IQueryable <UserSettingsViewModel> model = users
                                                       .Select(u => new UserSettingsViewModel {
                ProviderUserKey = u.Id,
                UserName        = u.UserName,
                Email           = u.Email,
                IsApproved      = u.IsApproved ? "Yes" : "No",
                IsLockedOut     = u.IsLockedOut ? "Yes" : "No",
                IsOnline        = (DbFunctions.DiffHours(u.LastLoginDate, DateTime.Now) < 1) ? "Yes" : "No",
                CreationDate    = u.CreateDate,
                LastLoginDate   = u.LastLoginDate
            })
                                                       .Where(u => !u.UserName.Contains("@"));

            // TODO: consider messaging user if no users were found

            return(View(model));
        }
        public async Task <IHttpActionResult> DailyStatistics()
        {
            using (var context = this.DataAccess.GetContext())
            {
                var offset = DateTime.Now.AddHours(-24);
                var start  = new DateTime(offset.Year, offset.Month, offset.Day, offset.Hour, 0, 0);
                var result = await context.NoTracking <DAL.Entities.QueryExecution>()
                             .Where(e => e.Start >= start)
                             .GroupBy(e => DbFunctions.DiffHours(start, e.Start))
                             .Select(g => new
                {
                    Hours      = g.Key,
                    Total      = g.Count(),
                    Successful = g.Count(e => e.Successful),
                    Failed     = g.Count(e => !e.Successful)
                })
                             .Select(x => new
                {
                    Hour       = DbFunctions.AddHours(start, x.Hours),
                    Total      = x.Total,
                    Successful = x.Successful,
                    Failed     = x.Failed
                })
                             .OrderBy(x => x.Hour)
                             .ToListAsync();

                return(this.Ok(result));
            }
        }
Пример #7
0
        public JsonResult GetDiaryEventsPersonal()
        {
            var depName   = Session["UserDepName"].ToString();
            var fullName  = Session["UserFullName"].ToString();
            var schedules = from s in db.Schedules.Include(s => s.Person).Include(s => s.Workplace).Where(s => s.active == true && s.Person.DictDepartment.Name == depName && s.Person.FullName == fullName)
                            join d in db.DictScheduleStatus.DefaultIfEmpty()
                            on s.ScheduleStatus equals d.Name
                            into temp
                            from d in temp.DefaultIfEmpty()
                            select new
            {
                s.ScheduleId,
                s.Person,
                s.DateStart,
                s.DateEnd,
                s.ScheduleStatus,
                colorHTML = d.ColorHTML == null ? "#FFFF92" : d.ColorHTML
            }
            ;
            var eventList = from e in schedules
                            select new
            {
                id          = e.ScheduleId,
                title       = e.Person.FullName,
                start       = e.DateStart,
                end         = e.DateEnd,
                description = e.ScheduleStatus,
                allDay      = (DbFunctions.DiffHours(e.DateStart, e.DateEnd) > 12) ? true : false,
                color       = e.colorHTML
            };
            var rows = eventList.ToArray();

            return(Json(rows, JsonRequestBehavior.AllowGet));
        }
        private static void coursesActiveOnGivenDate(StudentSystemContext context)
        {
            Console.Write("Enter Date: ");
            var input = Console.ReadLine();
            DateTime date;
            DateTime.TryParse(input, out date);

            var courses = context.Courses
                .Where(c => DbFunctions.TruncateTime(c.StartDate) <= date &&
                            DbFunctions.TruncateTime(c.EndDate) >= date)
                .Select(c => new
                {
                    Name = c.Name,
                    StartDate = c.StartDate,
                    EndDate = c.EndDate,
                    Duration = DbFunctions.DiffHours(c.StartDate, c.EndDate),
                    StudentsEnrolled = c.Students.Count
                })
                .OrderByDescending(c => c.StudentsEnrolled)
                .ThenByDescending(c => c.Duration)
                .ToArray();

            foreach (var course in courses)
            {
                Console.WriteLine($"Course name: {course.Name}");
                Console.WriteLine($"Course start date: {course.StartDate}");
                Console.WriteLine($"Course end date: {course.EndDate}");
                Console.WriteLine($"Course duration in days: {course.Duration}");
                Console.WriteLine($"Students nrolled for this course: {course.StudentsEnrolled}");
                Console.WriteLine("=================================");
            }
        }
        public bool ValidateAppointment(DateTime apptDate, int id)
        {
            var isAvailable = _db.Appointments.Any(m => DbFunctions.DiffHours(m.StartDateTime, apptDate) == 1 ||
                                                   DbFunctions.DiffHours(DbFunctions.AddHours(m.StartDateTime, -1), apptDate) == 1 ||
                                                   m.StartDateTime == apptDate && m.DoctorId == id && m.DStatus == true);

            return(isAvailable);
        }
        public void DbFunctionsTests_DiffHours_DateTime_Test()
        {
            DateTime testDateTime2 = this.TestDateTime.AddHours(1);

            var result = this.GetOrderQuery().Select(x => DbFunctions.DiffHours(this.TestDateTime, testDateTime2)).First();

            Assert.AreEqual(-1, result);
        }
Пример #11
0
        // Testing for work item 4341: Display Company News items with
        // Expiration dates that have not yet occurred, or are NULL.
        public ActionResult UnexpiredNews()
        {
            var data = db.CompanyNews
                       .Where(x => !x.ExpirationDate.HasValue ||
                              DbFunctions.DiffHours(x.ExpirationDate, DateTime.Now) <= 0);

            return(View(data.ToList()));
        }
Пример #12
0
        public ActionResult BannerHomeProduct()
        {
            var banners = _bannerService.FindBy(
                x => x.Status == 1 && x.PageBanner.Position == 10 &&
                (!x.FromDate.HasValue || DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) >= 0) &&
                (!x.ToDate.HasValue || DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) <= 0));

            return(PartialView(banners));
        }
Пример #13
0
        private IQueryable <Vehicle> Filter(string searchProp, string searchValue)
        {
            var Vehicles = db.Vehicles.Select(e => e);

            if (searchProp == "RegNumber")
            {
                Vehicles = Vehicles.Where(e => e.RegNumber.Contains(searchValue));
            }
            else if (searchProp == "Type")
            {
                Vehicles = Vehicles.Where(e => e.VehicleType.VehicleSort == searchValue);
            }
            else if (searchProp == "TimeParkedMore")
            {
                int dateTime;
                if (int.TryParse(searchValue, out dateTime))
                {
                    Vehicles = Vehicles.Where(e => (DbFunctions.DiffHours(e.CheckInTime, DateTime.Now) >= dateTime));
                }
            }
            else if (searchProp == "TimeParkedLess")
            {
                int dateTime;
                if (int.TryParse(searchValue, out dateTime))
                {
                    Vehicles = Vehicles.Where(e => (DbFunctions.DiffHours(e.CheckInTime, DateTime.Now) <= dateTime));
                }
            }
            else if (searchProp == "Member")
            {
                Vehicles = Vehicles.Where(e => e.Member.Name.Contains(searchValue));
            }
            else if (searchProp == "Membership")
            {
                Vehicles = Vehicles.Where(e => e.Member.Status.ToString() == searchValue);
            }
            //else if (searchProp == "CheckInTime") Vehicles = Vehicles.Where(e => e.CheckInTime == searchValue);
            else if (searchProp == "ParkingSlot")
            {
                Vehicles = Vehicles.Where(e => e.ParkingSlot.ToString() == searchValue);
            }
            else if (searchProp == "Terrain")
            {
                Vehicles = Vehicles.Where(e => e.VehicleType.TransportMedium == searchValue);
            }
            else if (searchProp == "Wheels")
            {
                Vehicles = Vehicles.Where(e => e.VehicleType.Wheels.ToString() == searchValue);
            }
            else if (searchProp == "Colour")
            {
                Vehicles = Vehicles.Where(e => e.Colour == searchValue);
            }
            return(Vehicles);
        }
Пример #14
0
        public ActionResult Index()

        {
            var query = from item in db.items                                       //只提取一天内的新闻
                        where DbFunctions.DiffHours(item.Date, DateTime.Now) < 24
                        select item;



            return(View(query.ToList()));
        }
Пример #15
0
        public ActionResult GetBannerMiddle(int?menuId)
        {
            var banners = _bannerService.FindBy(x =>
                                                x.MenuId == menuId && x.PageBanner.Position == 6 && x.Status == 1 &&
                                                (!x.FromDate.HasValue ||
                                                 DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) >= 0) &&
                                                (!x.ToDate.HasValue ||
                                                 DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) <= 0));

            return(PartialView(banners));
        }
Пример #16
0
        public static List <UserAction> GetUserActions(int hours)
        {
            using (var db = new WorktripEntities())
            {
                var utcNow = DateTime.UtcNow;

                var actions = db.UserActionsLogs.Where(a => DbFunctions.DiffHours(a.Timestamp.Value, utcNow) <= hours).ToList();

                var userList = actions.Select(a => a.UserId).ToList();

                var userInfoDict =
                    (from u in db.Users
                     where userList.Contains(u.Id)
                     join up in db.UserToPreparers on u.Id equals up.UserId into upJoined
                     from upj in upJoined.DefaultIfEmpty()
                     join s in db.Status on upj.StatusId equals s.Id into sJoined
                     from sj in sJoined.DefaultIfEmpty()
                     group new { u, upj, sj } by upj.UserId into g
                     select new UserSmallInfo
                {
                    Id = g.FirstOrDefault().u.Id,
                    PhoneNumber = g.FirstOrDefault().u.PhoneNumber,
                    FirstName = g.FirstOrDefault().u.FirstName,
                    MiddleName = g.FirstOrDefault().u.MiddleName,
                    LastName = g.FirstOrDefault().u.LastName,
                    Email = g.FirstOrDefault().u.Email,
                    Status = g.FirstOrDefault().sj.Name == null ? "Waiting for Assignment to Preparer" : g.FirstOrDefault().sj.Name,
                    Price = g.FirstOrDefault().upj.Fee,
                    PreparerId = g.FirstOrDefault().upj.PreparerId,
                    Color = g.FirstOrDefault().upj.ColorCode
                }).ToDictionary(u => u.Id, u => u);

                var result =
                    from a in actions
                    select new UserAction
                {
                    Id          = userInfoDict[a.UserId].Id,
                    PhoneNumber = userInfoDict[a.UserId].PhoneNumber,
                    FirstName   = userInfoDict[a.UserId].FirstName,
                    MiddleName  = userInfoDict[a.UserId].MiddleName,
                    LastName    = userInfoDict[a.UserId].LastName,
                    Email       = userInfoDict[a.UserId].Email,
                    Status      = userInfoDict[a.UserId].Status,
                    Price       = userInfoDict[a.UserId].Price,
                    PreparerId  = userInfoDict[a.UserId].PreparerId,
                    Color       = userInfoDict[a.UserId].Color,
                    Action      = a.Action,
                    TimeStr     = DateTime.SpecifyKind(a.Timestamp.Value, DateTimeKind.Utc).ToString("s") + "Z"
                };

                return(result.ToList());
            }
        }
Пример #17
0
    public IEnumerable <ComputerStatisticByUsingUnit> GetComputerStatisticByUsingUnit()
    {
        var totalHour = DbContext.ComputerUsingHistories.Sum(x => DbFunctions.DiffHours(x.StartTime, x.EndTime)).Value;
        var query     = DbContext.ComputerUsingHistories.GroupBy(x => x.Computer.ComputerName).Select(x => new ComputerStatisticByUsingUnit
        {
            ComputerName = x.Key,
            //UsingUnit = x.Sum(y => DbFunctions.DiffHours(y.StartTime, y.EndTime).Value)
            Percent = Math.Round((double)(x.Sum(y => DbFunctions.DiffHours(y.StartTime, y.EndTime).Value)) / totalHour * 100, 3)
        });

        return(query.OrderBy(x => x.ComputerName).ToList());
    }
Пример #18
0
        public PriceTable IfFirstOrNo(string coinname, DateTime time)
        {
            var _where = PredicateBuilder.New <PriceTable>();

            _where = _where.And(u => u.CoinToCoin == coinname);
            var a = DateTime.Now.ToString("yyyy/MM/dd");

            _where = _where.And(p => DbFunctions.DiffHours(p.KDateTime, time) < 24);
            PriceTable pt = Repository.Find(_where);

            return(pt);
        }
Пример #19
0
        public async Task <ChartItem[]> GetChartForEndpointLastHours(long endpointId, int hours = 10)
        {
            var now = DateTime.UtcNow;

            return(await _healthReportRepository
                   .Query()
                   .Where(x => x.EndpointId == endpointId && DbFunctions.DiffHours(x.Timestamp, now) < hours && x.ResponseTime != null)
                   .Select(x => new ChartItem {
                Time = x.Timestamp, Response = x.ResponseTime.Value
            })
                   .OrderBy(x => x.Time)
                   .ToArrayAsync());
        }
Пример #20
0
 internal List <Commande> CommandesAStatuer()
 {
     using (foodtruckEntities db = new foodtruckEntities())
     {
         DateTime  now           = DateTime.Now;
         const int intervalleMax = 1;
         var       commandes     = (from cmd in db.Commande
                                    where !cmd.Retrait && !cmd.Annulation && DbFunctions.DiffHours(cmd.DateRetrait, now) >= intervalleMax
                                    orderby cmd.DateRetrait
                                    select cmd).ToList();
         return(commandes);
     }
 }
Пример #21
0
        public ActionResult BannerTopOfNewsPage(int?menuId, string title)
        {
            var banners = _bannerService.FindBy(x =>
                                                x.MenuId == menuId && x.Status == 1 && x.PageBanner.Position == 1 &&
                                                (!x.FromDate.HasValue ||
                                                 DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) >= 0) &&
                                                (!x.ToDate.HasValue ||
                                                 DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) <= 0));

            ViewBag.Title = title;

            return(PartialView(banners));
        }
        public IQueryable <CurrencyRateByTime> GetAllActual()
        {
            var allRates = _currencyRateByTimeRepository.GetAll();
            var span     = new TimeSpan(4, 0, 0).TotalHours;
            var now      = DateTime.UtcNow;
            var result   = allRates.Where(x =>
                                          DbFunctions.DiffMonths(now, x.DateTime) == 0 &&
                                          DbFunctions.DiffYears(now, x.DateTime) == 0 &&
                                          DbFunctions.DiffDays(now, x.DateTime) == 0 &&
                                          DbFunctions.DiffHours(x.DateTime, now) < span);

            return(result);
        }
        public void DateFunctions()
        {
            using (var context = new BloggingContext(ConnectionString))
            {
                IQueryable <int> oneRow = context.Posts.Where(p => false).Select(p => 1).Concat(new int[] { 1 });

                var dateAdds = oneRow.Select(p => new List <DateTime?>
                {
                    DbFunctions.AddDays(new DateTime(2014, 2, 28), 1),
                    DbFunctions.AddHours(new DateTime(2014, 2, 28, 23, 0, 0), 1),
                    DbFunctions.AddMinutes(new DateTime(2014, 2, 28, 23, 59, 0), 1),
                    DbFunctions.AddSeconds(new DateTime(2014, 2, 28, 23, 59, 59), 1),
                    DbFunctions.AddMilliseconds(new DateTime(2014, 2, 28, 23, 59, 59, 999), 2 - p),
                    DbFunctions.AddMicroseconds(DbFunctions.AddMicroseconds(new DateTime(2014, 2, 28, 23, 59, 59, 999), 500), 500),
                    DbFunctions.AddNanoseconds(new DateTime(2014, 2, 28, 23, 59, 59, 999), 999999 + p),
                    DbFunctions.AddMonths(new DateTime(2014, 2, 1), 1),
                    DbFunctions.AddYears(new DateTime(2013, 3, 1), 1)
                }).First();
                foreach (var result in dateAdds)
                {
                    Assert.IsTrue(result.Value == new DateTime(2014, 3, 1, 0, 0, 0));
                }

                var dateDiffs = oneRow.Select(p => new {
                    a = DbFunctions.DiffDays(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    b = DbFunctions.DiffHours(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    c = DbFunctions.DiffMinutes(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    d = DbFunctions.DiffSeconds(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    e = DbFunctions.DiffMilliseconds(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    f = DbFunctions.DiffMicroseconds(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    g = DbFunctions.DiffNanoseconds(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(2000, 1, 1, 0, 0, 0)),
                    h = DbFunctions.DiffMonths(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(3000, 1, 1, 0, 0, 0)),
                    i = DbFunctions.DiffYears(new DateTime(1999, 12, 31, 23, 59, 59, 999), new DateTime(3000, 1, 1, 0, 0, 0)),
                    j = DbFunctions.DiffYears(null, new DateTime(2000, 1, 1)),
                    k = DbFunctions.DiffMinutes(new TimeSpan(1, 2, 3), new TimeSpan(4, 5, 6)),
                    l = DbFunctions.DiffMinutes(new TimeSpan(1, 2, 3), null)
                }).First();
                Assert.AreEqual(dateDiffs.a, 1);
                Assert.AreEqual(dateDiffs.b, 1);
                Assert.AreEqual(dateDiffs.c, 1);
                Assert.AreEqual(dateDiffs.d, 1);
                Assert.AreEqual(dateDiffs.e, 1);
                Assert.AreEqual(dateDiffs.f, 1000);
                Assert.AreEqual(dateDiffs.g, 1000000);
                Assert.AreEqual(dateDiffs.h, 12001);
                Assert.AreEqual(dateDiffs.i, 1001);
                Assert.AreEqual(dateDiffs.j, null);
                Assert.AreEqual(dateDiffs.k, 183);
                Assert.AreEqual(dateDiffs.l, null);
            }
        }
Пример #24
0
        public JsonResult Entrust()
        {   //按ID分组 查找出所有交易对各自的数量 交易笔
            var    pd   = _priceInADealManager.FindList(p => DbFunctions.DiffHours(p.DealTime, DateTime.Now) < 24).GroupBy(u => u.PriceInDayID).ToList();
            string name = null;
            List <EntrustDataSet> eds         = new List <EntrustDataSet>();
            List <string>         edsCoinName = new List <string>();
            List <string>         cointocoin  = new List <string>();
            //找出所有交易对名称
            var list = _priceInDaymanager.FindList().ToList().Select(u => u.CoinToCoin);

            foreach (var item in list)
            {
                cointocoin.Add(item);
            }
            ;
            //将分组情况添加到json类中
            foreach (var i in pd)
            {
                foreach (var item in i)
                {
                    name = _priceInDaymanager.Find(item.PriceInDayID).CoinToCoin;
                    break;
                }
                eds.Add(new EntrustDataSet {
                    count    = i.Count(),
                    amount   = i.Sum(u => u.Amount),
                    coinname = name
                });
            }
            ;
            foreach (var item in eds)
            {
                edsCoinName.Add(item.coinname);
            }
            //如果某交易对无交易 添加默认
            foreach (var item in cointocoin)
            {
                if (edsCoinName == null || !edsCoinName.Contains(item))
                {
                    eds.Add(new EntrustDataSet
                    {
                        count    = 0,
                        amount   = 0,
                        coinname = item
                    });
                }
                ;
            }

            return(Json(eds));
        }
        public int Add(IFlight entity)
        {
            int id = RepositoryMethods.Add <Flight>(this.context,
                                                    (Flight)entity,
                                                    x => DbFunctions.DiffYears(x.SheduledTime, entity.SheduledTime) == 0 &&
                                                    DbFunctions.DiffMonths(x.SheduledTime, entity.SheduledTime) == 0 &&
                                                    DbFunctions.DiffDays(x.SheduledTime, entity.SheduledTime) == 0 &&
                                                    DbFunctions.DiffHours(x.SheduledTime, entity.SheduledTime) == 0 &&
                                                    DbFunctions.DiffMinutes(x.SheduledTime, entity.SheduledTime) == 0 &&
                                                    x.DestinationAirportId == entity.DestinationAirportId &&
                                                    x.FlightTypeId == entity.FlightTypeId);

            return(id);
        }
Пример #26
0
    public HttpResponseMessage GetTrip(int id)
    {
        try
        {
            var timezone = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");

            var date = TimeZoneInfo.ConvertTime(DateTime.Now, timezone);

            var trip = context.trips.Where(t => t.ID == id)
                       .Join(context.UserMasters, t => t.DriverId, u => u.UserID, (tr, us) => new
                {
                    DateOfTrip  = tr.DateOfTrip,
                    DriverId    = tr.DriverId,
                    FromCity    = tr.FromCity,
                    ID          = tr.ID,
                    PlaceToMeet = tr.PlaceToMeet,
                    TimeOfTrip  = tr.TimeOfTrip,
                    ToCity      = tr.ToCity,
                    Name        = (us.FullName == null) ? us.UserName : us.FullName,
                    ImageUrl    = us.ImageUrl,
                    PostTime    = (DbFunctions.TruncateTime(tr.TimeOfPost) == DbFunctions.TruncateTime(date)) ?
                                  (tr.TimeOfPost.Value.Hour == date.Hour ?
                                   new { time = DbFunctions.DiffMinutes(tr.TimeOfPost.Value, date).Value, unit = "Minutes" } :
                                   new { time = DbFunctions.DiffHours(tr.TimeOfPost.Value, date).Value, unit = "hours" }) :
                                  new { time = DbFunctions.DiffDays(tr.TimeOfPost.Value, date).Value, unit = "days" }
                }).FirstOrDefault();
            if (trip == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Requested trip not found"));
            }
            var tripToReturn = new {
                DateOfTrip  = trip.DateOfTrip.ToString("MM/dd/yyyy"),
                DriverId    = trip.DriverId,
                FromCity    = trip.FromCity,
                ID          = trip.ID,
                PlaceToMeet = trip.PlaceToMeet,
                TimeOfTrip  = trip.TimeOfTrip.Hours + ":" + trip.TimeOfTrip.Minutes,
                ToCity      = trip.ToCity,
                Name        = trip.Name,
                ImageUrl    = trip.ImageUrl,
                PostTime    = trip.PostTime
            };
            return(Request.CreateResponse(HttpStatusCode.OK, tripToReturn));
        }
        catch (Exception ex) {
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
        }
    }
Пример #27
0
        public Banner GetBanner(int?menuId = null, int status = 1, List <int> position = null, bool isCache = true)
        {
            var sbKey = new StringBuilder();

            sbKey.AppendFormat(CacheKey, "GetBanner");

            var expression = PredicateBuilder.True <Banner>();

            expression = expression.And(x => x.Status == status);
            sbKey.AppendFormat("-{0}", status);

            if (menuId != null)
            {
                sbKey.AppendFormat("-{0}", menuId);
                expression = expression.And(x => x.MenuId == menuId);
            }

            if (position.IsAny())
            {
                var i = 0;
                foreach (var pos in position)
                {
                    sbKey.AppendFormat("-{0}", pos);
                    expression = i == 0 ? expression.And(x => x.PageBanner.Position == pos) : expression.Or(x => x.PageBanner.Position == pos);
                    i++;
                }
            }

            //Where from date and to date
            expression = expression.And(x => (!x.FromDate.HasValue || DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) >= 0) &&
                                        (!x.ToDate.HasValue || DbFunctions.DiffHours(x.ToDate.Value, DateTimeOffset.UtcNow.Offset) <= 0));

            if (!isCache)
            {
                return(_bannerRepository.Get(expression));
            }

            var key    = sbKey.ToString();
            var banner = _cacheManager.Get <Banner>(key);

            if (banner == null)
            {
                banner = _bannerRepository.Get(expression);
                _cacheManager.Put(key, banner);
            }

            return(banner);
        }
Пример #28
0
        public void TimeDiffHours()
        {
            TimeSpan time = stored.Add(TimeSpan.FromHours(-1));

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.DiffHours(time, x.Time) == 1);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.DiffHours(time, x.Time) == 1);
#endif

            q.Should().NotBeEmpty();
        }
        public void DateTimeDiffHours()
        {
            DateTime date = stored.AddHours(-1);

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.DiffHours(date, x.DateTime) == 1);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.DiffHours(date, x.DateTime) == 1);
#endif

            q.Should().NotBeEmpty();
        }
Пример #30
0
        public void DateTimeOffsetDiffHours()
        {
            DateTimeOffset offset = stored.AddHours(-1);

#if !EFOLD
            var q = this.Entities
                    .Where(x =>
                           DbFunctions.DiffHours(offset, x.Offset) == 1);
#else
            var q = this.Entities
                    .Where(x =>
                           EntityFunctions.DiffHours(offset, x.Offset) == 1);
#endif

            q.Should().NotBeEmpty();
        }