private JourExceptionnel AjouterPeriodeExceptionnelle(DateTime dateDebut, DateTime dateFin, bool ouvert)
 {
     using (foodtruckEntities db = new foodtruckEntities())
     {
         JourExceptionnel chevauchement = (from j in db.JourExceptionnel
                                           where DbFunctions.DiffMinutes(j.DateDebut, dateFin) >= 0 && DbFunctions.DiffMinutes(dateDebut, j.DateFin) >= 0
                                           select j).FirstOrDefault();
         if (chevauchement == null)
         {
             JourExceptionnel jour = new JourExceptionnel
             {
                 DateDebut = dateDebut,
                 DateFin   = dateFin,
                 Ouvert    = ouvert,
             };
             db.JourExceptionnel.Add(jour);
             db.SaveChanges();
         }
         return(chevauchement);
     }
 }
        private JourExceptionnel ModifierPeriodeExceptionnelle(DateTime dateId, DateTime dateDebut, DateTime dateFin, bool ouvert)
        {
            using (foodtruckEntities db = new foodtruckEntities())
            {
                JourExceptionnel jourSelectionne = (from j in db.JourExceptionnel
                                                    where j.DateDebut == dateId && j.Ouvert == ouvert
                                                    select j).FirstOrDefault();

                JourExceptionnel chevauchement = (from j in db.JourExceptionnel
                                                  where j.DateDebut != jourSelectionne.DateDebut && DbFunctions.DiffMinutes(j.DateDebut, dateFin) > 0 && DbFunctions.DiffMinutes(dateDebut, j.DateFin) > 0
                                                  select j).FirstOrDefault();

                if (chevauchement == null && jourSelectionne != null)
                {
                    jourSelectionne.DateDebut = dateDebut;
                    jourSelectionne.DateFin   = dateFin;
                    jourSelectionne.Ouvert    = ouvert;
                    db.SaveChanges();
                }
                return(chevauchement);
            }
        }
 public void DbFunctionsTests_DiffMinutes_DateTimeOffset_Test()
 {
     this.AssertException <NotSupportedException>(() => {
         this.GetOrderQuery().Select(x => DbFunctions.DiffMinutes(this.TestDateTimeOffset, this.TestDateTimeOffset)).First();
     });
 }
Example #4
0
        private void RankingScheduler()
        {
            Action timertask = new Action(() =>
            {
                _logger.LogInformation("Starting Ranking Scheduler!");
                using (var scope = _scopeFactory.CreateScope())
                {
                    var db         = scope.ServiceProvider.GetRequiredService <BlogContext>();
                    var sincemonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                    if (DateTime.Today.Day != 1) // Show last month on day 1
                    {
                        var ranking1month = GetRankingSinceDate(db, sincemonth, DateTime.Today, HistoryRanking.Type.RankMonthly);
                        db.HistoryRankings.RemoveRange(db.HistoryRankings.Where(h => h.RankType == HistoryRanking.Type.RankMonthly && DbFunctions.DiffMonths(h.RankDate, sincemonth) == 0));
                        db.HistoryRankings.AddRange(ranking1month);
                    }

                    var rankings24h = db.Blogs.Where(b => !NoRankCategories.Contains(b.CategoryID) && DbFunctions.DiffMinutes(b.BlogDate, DateTime.Now) < 1440 && b.isApproved == true)
                                      .OrderByDescending(r => r.Rating)
                                      .ThenByDescending(r => r.BlogDate)
                                      .Take(RankSize)
                                      .Select(b => new
                    {
                        blog      = b,
                        rating    = b.Rating ?? 0,
                        postCount = db.Posts.Count(p => p.IdType == ItemType.Blog && p.ItemId == b.BlogID)
                    }).ToList()
                                      .Select(r => new HistoryRanking
                    {
                        Rating    = r.rating,
                        PostCount = r.postCount,
                        Author    = r.blog.Author,
                        BlogVisit = r.blog.BlogVisit,
                        BlogTitle = r.blog.BlogTitle,
                        BlogThumb = BlogHelper.firstImgPath(r.blog, true),
                        BlogID    = r.blog.BlogID,
                        BlogDate  = r.blog.BlogDate,
                        RankDate  = DateTime.Now,
                        RankType  = HistoryRanking.Type.Rank24h
                    });
                    db.HistoryRankings.RemoveRange(db.HistoryRankings.Where(h => h.RankType == HistoryRanking.Type.Rank24h));
                    db.HistoryRankings.AddRange(rankings24h);

                    var dayFromMonday = DateTime.Now.DayOfWeek - DayOfWeek.Monday;
                    if (dayFromMonday < 0)
                    {
                        dayFromMonday += 7;
                    }
                    var firstday = DateTime.Today.AddDays(-dayFromMonday);
                    // remove this week's data.
                    db.HistoryRankings.RemoveRange(db.HistoryRankings.Where(h => h.RankType == HistoryRanking.Type.RankWeekly && firstday <= h.RankDate));
                    if (dayFromMonday == 0) //if today is monday reuse last week data.
                    {
                        var lastWeek = GetRankingSinceDate(db, firstday.AddDays(-7), DateTime.Today, HistoryRanking.Type.RankWeekly);
                        db.HistoryRankings.AddRange(lastWeek);
                    }
                    else
                    {
                        var rankings7d = GetRankingSinceDate(db, firstday, DateTime.Today, HistoryRanking.Type.RankWeekly);
                        db.HistoryRankings.AddRange(rankings7d);
                    }
                    db.SaveChanges();
                }
            });

            Schedule(timertask).WithName(RankingTask).ToRunEvery(UpdateInterval).Minutes();
        }
Example #5
0
        private bool checkTimes(DateTime aimTime, string fileBasePath, string fileName, out int gCount, out List <stock_alarm_GSA> goodsList)
        {
            gCount = 0;
            using (ksoaContext db = new ksoaContext())
            {
                var query = from q in db.stock_alarm_GSA  where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan select q;

                var query1 = from q in query
                             where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan
                             from p in db.spkfks
                             from r in db.huoweizls
                                                                    //from s in db.hwsps
                             where q.spid == p.spid && r.hw == q.hw //&&q.spid==s.spid&&q.hw==s.hw
                             select new
                {                                                   //18335768012    462045
                    ID   = q.ID,
                    商品编号 = q.spbh,
                    商品名称 = q.spmch,
                    货位   = r.huowname,
                    一级分类 = p.yjfl,
                    二级分类 = p.ejfl,
                    级分类  = p.sjfl,
                    预警阈值 = (int)(q.threshold_value),
                    //实时库存= (int)s.hwshl,
                    计算时库存   = (int)q.amount_static,
                    近1月总销量  = q.saledIn1Month,
                    近7天销量   = q.saledIn7Days,
                    预计五天后库存 = q.stock_5DLatter,
                    在途数量    = q.stock_transit,
                    预计补货量   = q.restock_count,
                    最大库存量   = (int)(q.amount_static + q.restock_count + q.stock_transit - q.delivery_cycle * (q.saledIn7Days / 7.0)),
                    安全库存量   = (int)(q.safty_days * (0.85 * (q.saledIn7Days / 7.0) + 0.15 * (q.saledIn1Month / 30.0))),
                    次预警时间   = q.last_alarmDate,
                    最后统计时间  = q.lastCalcuDate
                };

                goodsList = query.ToList();
                gCount    = goodsList.Count();
                if (gCount > 0)
                {
                    OpenXmlExcelOper.CreateSpreadSheet(fileBasePath + fileName, "data");
                    OpenXmlExcelOper.FillAlarmData(fileBasePath + fileName, "data", ListToDataTable(query1.ToList()));
                }
            }
            return(true);
        }
 public void DbFunctionsTests_DiffMinutes_TimeSpan_Test()
 {
     this.AssertException <NotSupportedException>(() => {
         this.GetOrderQuery().Select(x => DbFunctions.DiffMinutes(this.TestTimeSpan, this.TestTimeSpan)).First();
     });
 }
Example #7
0
    public HttpResponseMessage GetAllTrips()
    {
        try
        {
            var timezone = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");

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


            var tripss = context.trips.Where(t => t.ID != context.Reservations.FirstOrDefault(r => r.TripId == t.ID).TripId).Join(context.UserMasters, t => t.DriverId, u => u.UserID,
                                                                                                                                  (tr, us) => new
                {
                    DateOfTrip  = DbFunctions.TruncateTime(tr.DateOfTrip).Value,
                    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" }
                }).OrderByDescending(p => p.ID).ToList();
            //var tripsAllTrips = context.trips.ToList();
            //var trips = context.trips.ToList().Select(tr => new
            //{
            //    UserName = context.UserMasters.Where(u => u.UserID == tr.DriverId).ToList().FirstOrDefault().UserName,
            //    DateOfTrip = tr.DateOfTrip,
            //    DriverId = tr.DriverId,
            //    FromCity = tr.FromCity,
            //    ID = tr.ID,
            //    PlaceToMeet = tr.PlaceToMeet,
            //    TimeOfTrip = tr.TimeOfTrip,
            //    ToCity = tr.ToCity


            //}).ToList();
            if (tripss == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "There is no trips"));
            }
            var tripssToReturn = tripss.Select(t => new {
                    DateOfTrip  = t.DateOfTrip.ToString("MM/dd/yyyy"),
                    DriverId    = t.DriverId,
                    FromCity    = t.FromCity,
                    ID          = t.ID,
                    PlaceToMeet = t.PlaceToMeet,
                    TimeOfTrip  = t.TimeOfTrip.Hours + ":" + t.TimeOfTrip.Minutes,
                    ToCity      = t.ToCity,
                    Name        = t.Name,
                    ImageUrl    = t.ImageUrl,
                    PostTime    = t.PostTime
                }).ToList();


            return(Request.CreateResponse(HttpStatusCode.OK, tripssToReturn));
        }
        catch (Exception ex)
        {
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
        }
    }
Example #8
0
        private bool checkTimes(DateTime aimTime, string fileBasePath, string fileName, out int gCount, out List <stock_alarm_GSA> goodsList)
        {
            gCount = 0;
            using (ksoaContext db = new ksoaContext())
            {
                var query = from q in db.stock_alarm_GSA where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan select q;

                var query1 = from q in query
                             where q.stock_5DLatter < q.threshold_value && q.alarm_state == 0 && DbFunctions.DiffMinutes(q.last_alarmDate, DateTime.Now) >= q.alarmSpan
                             from p in db.spkfks
                             from r in db.huoweizls
                             where q.spid == p.spid && r.hw == q.hw
                             select new
                {
                    ID     = q.ID,
                    商品编号   = q.spbh,
                    商品名称   = q.spmch,
                    货位     = r.huowname,
                    一级分类   = p.yjfl,
                    二级分类   = p.ejfl,
                    级分类    = p.sjfl,
                    预警阈值   = q.threshold_value,
                    五日后库存  = q.stock_5DLatter,
                    最后统计时间 = q.lastCalcuDate,
                    次预警时间  = q.last_alarmDate,
                    近两个月销量 = q.saledIn2Month,
                    近一月销量  = q.saledIn1Month,
                };

                goodsList = query.ToList();
                gCount    = goodsList.Count();
                if (gCount > 0)
                {
                    OpenXmlExcelOper.CreateSpreadSheet(fileBasePath + fileName, "data");
                    OpenXmlExcelOper.FillAlarmData(fileBasePath + fileName, "data", ListToDataTable(query1.ToList()));
                }
            }
            return(true);
        }
Example #9
0
    public HttpResponseMessage GetMyReservedTrips()
    {
        try
        {
            var timezone = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");

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


            var currentUserID = context.UserMasters.FirstOrDefault(u => u.UserName == (RequestContext.Principal.Identity.Name)).UserID;


            var ReservedTripsOfCurrentUser = context.trips
                                             .Join(context.Reservations, t => t.ID, r => r.TripId, (tr, re) => new {
                    DateOfTrip  = DbFunctions.TruncateTime(tr.DateOfTrip).Value,
                    DriverId    = tr.DriverId,
                    FromCity    = tr.FromCity,
                    TripID      = tr.ID,
                    PlaceToMeet = tr.PlaceToMeet,
                    TimeOfTrip  = tr.TimeOfTrip,
                    ToCity      = tr.ToCity,
                    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" },
                    re.TravellerId,
                    re.Accebted
                }).Where(t => DbFunctions.TruncateTime(date) < DbFunctions.TruncateTime(t.DateOfTrip) && currentUserID == t.TravellerId)
                                             .Join(context.UserMasters, t => t.DriverId, u => u.UserID, (tr, us) => new
                {
                    DateOfTrip  = tr.DateOfTrip,
                    DriverId    = tr.DriverId,
                    FromCity    = tr.FromCity,
                    TripID      = tr.TripID,
                    PlaceToMeet = tr.PlaceToMeet,
                    TimeOfTrip  = tr.TimeOfTrip,
                    ToCity      = tr.ToCity,
                    PostTime    = tr.PostTime,
                    tr.TravellerId,
                    Accebted = tr.Accebted == true ?
                               "Accepted reservation" : "reservation not yet Accepted ",
                    Name     = (us.FullName == null) ? us.UserName : us.FullName,
                    ImageUrl = us.ImageUrl
                }).OrderByDescending(p => p.TripID).ToList();

            //var ReservedTrips = context.trips.Join(context.UserMasters, t => t.DriverId, u => u.UserID,
            //(tr, us) => new
            //{
            //    DateOfTrip = DbFunctions.TruncateTime(tr.DateOfTrip).Value,
            //    DriverId = tr.DriverId,
            //    FromCity = tr.FromCity,
            //    ID = tr.ID,
            //    PlaceToMeet = tr.PlaceToMeet,
            //    TimeOfTrip = tr.TimeOfTrip,
            //    ToCity = tr.ToCity,
            //    Accebted=context.Reservations.FirstOrDefault(r=>r.TripId==tr.ID).Accebted.Value==true?
            //    "Accepted reservation": "reservation not yet Accepted "
            //    ,
            //    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" }

            //}) .OrderByDescending(p => p.ID).ToList();
            if (ReservedTripsOfCurrentUser == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, "there is no Reserved trips"));
            }
            var tripssToReturn = ReservedTripsOfCurrentUser.Select(t => new {
                    DateOfTrip  = t.DateOfTrip.ToString("MM/dd/yyyy"),
                    DriverId    = t.DriverId,
                    FromCity    = t.FromCity,
                    ID          = t.TripID,
                    PlaceToMeet = t.PlaceToMeet,
                    TimeOfTrip  = t.TimeOfTrip.Hours + ":" + t.TimeOfTrip.Minutes,
                    t.Accebted,
                    ToCity   = t.ToCity,
                    Name     = t.Name,
                    ImageUrl = t.ImageUrl,
                    PostTime = t.PostTime
                }).ToList();
            return(Request.CreateResponse(HttpStatusCode.OK, tripssToReturn));
        }
        catch (Exception ex)
        {
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
        }
    }
Example #10
0
    public HttpResponseMessage SearchForTrip(SearchForTripDto searchDto)
    {
        if (ModelState.IsValid)
        {
            try
            {
                var timezone = TimeZoneInfo.FindSystemTimeZoneById("Egypt Standard Time");

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

                var ResultTripsOfSearch = context.trips.Where
                                              (t => DbFunctions.TruncateTime(t.DateOfTrip) == DbFunctions.TruncateTime(searchDto.DateOfTrip) && t.FromCity == searchDto.FromCity && t.ToCity == searchDto.ToCity)
                                          .Join(context.UserMasters, t => t.DriverId, u => u.UserID, (tr, us) => new
                    {
                        DateOfTrip  = DbFunctions.TruncateTime(tr.DateOfTrip).Value,
                        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" }
                    }).ToList();
                var tripsEditDate = ResultTripsOfSearch.Select(t => new
                    {
                        DateOfTrip  = t.DateOfTrip.ToString("MM/dd/yyyy"),
                        DriverId    = t.DriverId,
                        FromCity    = t.FromCity,
                        ID          = t.ID,
                        PlaceToMeet = t.PlaceToMeet,
                        TimeOfTrip  = t.TimeOfTrip.Hours + ":" + t.TimeOfTrip.Minutes,
                        ToCity      = t.ToCity,
                        Name        = t.Name,
                        ImageUrl    = t.ImageUrl,
                        PostTime    = t.PostTime
                    });

                if (ResultTripsOfSearch == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "There is no trips"));
                }
                var tripssToReturn = ResultTripsOfSearch.
                                     Join(context.Reservations, t => t.ID, r => r.TripId, (t, r) =>
                                          new
                    {
                        DateOfTrip  = t.DateOfTrip,
                        DriverId    = t.DriverId,
                        FromCity    = t.FromCity,
                        ID          = t.ID,
                        PlaceToMeet = t.PlaceToMeet,
                        TimeOfTrip  = t.TimeOfTrip,
                        ToCity      = t.ToCity,
                        Name        = t.Name,
                        ImageUrl    = t.ImageUrl,
                        PostTime    = t.PostTime
                    }).ToList();
                var triptoreturn = tripssToReturn.Select(t => new
                    {
                        DateOfTrip  = t.DateOfTrip.ToString("MM/dd/yyyy"),
                        DriverId    = t.DriverId,
                        FromCity    = t.FromCity,
                        ID          = t.ID,
                        PlaceToMeet = t.PlaceToMeet,
                        TimeOfTrip  = t.TimeOfTrip.Hours + ":" + t.TimeOfTrip.Minutes,
                        ToCity      = t.ToCity,
                        Name        = t.Name,
                        ImageUrl    = t.ImageUrl,
                        PostTime    = t.PostTime
                    });
                List <object> listToRet = new List <object>();
                bool          found     = false;
                object        ObjToAdd;
                for (int i = 0; i < tripsEditDate.Count(); i++)
                {
                    for (int j = 0; j < tripssToReturn.Count(); j++)
                    {
                        if (tripsEditDate.ElementAt(i).ID == tripssToReturn.ElementAt(j).ID)
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        listToRet.Add(tripsEditDate.ElementAt(i));
                    }
                    found = false;
                }


                return(Request.CreateResponse(HttpStatusCode.OK, listToRet));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "you have to fill required fields"));
    }
        public ActionResult GetNotificationsData()
        {
            var currentUserId = User.Identity.GetUserId();

            var notificationsData = new List <NotificationsModel>();

            var currentUserIds = this.eventsUsers.All().Where(x => x.UserID == currentUserId && x.Status == EventUserStatus.Enrolled).Select(x => x.EventID).ToList();;

            var upcomingEvents = this.eventsUsers.All().Where(x => x.UserID == currentUserId && x.Status == EventUserStatus.Enrolled && DbFunctions.DiffHours(DateTime.Now, x.EventId.StartDate) < 24 && DbFunctions.DiffMinutes(DateTime.Now, x.EventId.StartDate) > 0).ToList();

            var upcomingLectures = this.lectures.All().Where(x => currentUserIds.Contains(x.EventId) && DbFunctions.DiffHours(DateTime.Now, x.Date) < 24 && DbFunctions.DiffMinutes(DateTime.Now, x.Date) > 0).Select(x => new CourseLectureViewModel
            {
                Id           = x.Id,
                EventId      = x.EventId,
                LectureDate  = x.Date,
                LectureTitle = x.Title
            });

            foreach (var ev in upcomingEvents)
            {
                notificationsData.Add(new NotificationsModel
                {
                    Id               = ev.EventID,
                    Title            = ev.EventId.Title,
                    StartDate        = ev.EventId.StartDate,
                    LectureId        = 0,
                    HoursRemaining   = (ev.EventId.StartDate - DateTime.Now).Hours,
                    MinutesRemaining = (ev.EventId.StartDate - DateTime.Now).Minutes,
                    TypeMessage      = base.GetLocalizedEventTypeString(ev.EventId.Type)
                });
            }

            foreach (var lecture in upcomingLectures)
            {
                notificationsData.Add(new NotificationsModel
                {
                    Id               = lecture.EventId,
                    Title            = lecture.LectureTitle,
                    StartDate        = lecture.LectureDate,
                    LectureId        = lecture.Id,
                    HoursRemaining   = (lecture.LectureDate - DateTime.Now).Hours,
                    MinutesRemaining = (lecture.LectureDate - DateTime.Now).Minutes,
                    TypeMessage      = string.Format("{0} {1} {2}", EventsTypes.Lecture, Global.From, EventsTypes.Course)
                });
            }

            //var currentUserEvents = this.eventsUsers.All().Where(x => x.UserID == currentUserId).ToList()
            //    .Select(x => new NotificationsModel
            //    {
            //        Id = x.EventID,
            //        Title = x.EventId.Title,
            //        LectureId = x.EventId.Lectures.
            //    });

            return(Json(notificationsData.OrderBy(x => x.StartDate).ThenBy(x => x.Title), JsonRequestBehavior.AllowGet));
        }
Example #12
0
        public IEnumerable <Todo> GetRecentTodos()
        {
            var currentTime = DateTime.Now;

            return(_db.Todos.Where(t => t.Status.Equals("Open") || DbFunctions.DiffMinutes(t.LastModified, currentTime) <= _timeInterval));
        }
Example #13
0
        public object Book(string userID, int facutlyID, int roomID, string timeStart, string timeEnd, string title, string content, string note, int numberPerson)
        {
            DateTime start = Convert.ToDateTime(timeStart);
            DateTime end   = Convert.ToDateTime(timeEnd);
            //var checkCoinCide = db.LineRooms.Where(x => x.RoomID == roomID
            //&& (start >= x.TimeStart && start <= x.TimeEnd)
            //|| (end >= x.TimeStart && end <= x.TimeEnd)
            //|| (start >= x.TimeStart && end <= x.TimeEnd)
            //).ToList();

            var checkCoinCide = db.LineRooms.Where(q => q.RoomID == roomID &&
                                                   ((DbFunctions.DiffMinutes(start, q.TimeStart) >= 0 && DbFunctions.DiffMinutes(end, q.TimeStart) <= 0) ||
                                                    (DbFunctions.DiffMinutes(start, q.TimeEnd) >= 0 && DbFunctions.DiffMinutes(end, q.TimeEnd) <= 0))
                                                   ).ToList();

            if (checkCoinCide.Count > 0)
            {
                return(new
                {
                    isBooking = false,
                    message = "Lịch họp bạn đặt đã trùng với một cuộc họp khác",
                });
            }

            LineRoom lineRoom = new LineRoom();

            lineRoom.LineRoomName = title;
            lineRoom.Content      = content;
            lineRoom.Description  = note;
            lineRoom.Status       = 1;

            lineRoom.TimeStart    = start;
            lineRoom.TimeEnd      = end;
            lineRoom.NumberPerson = numberPerson;
            lineRoom.CreateBy     = userID;
            lineRoom.CreateTime   = DateTime.Now;
            lineRoom.RoomID       = roomID;
            db.LineRooms.Add(lineRoom);
            try
            {
                db.SaveChanges();
                return(new
                {
                    isBooking = true,
                    message = "Bạn đã đặt phòng họp thành công",
                    result = new LineRoomDao().GetLineRoomByRoomID(roomID)
                });
            }
            catch
            {
                return(new
                {
                    isBooking = false,
                    message = "Lỗi hệ thống! Vui lòng thử lại",
                });
            }
        }
        private Table GetFreeTable(DateTime orderDate)
        {
            var allReservations = UnitOfWork.All <ReservationOrder>();
            var table           =
                UnitOfWork.GetActual <Table>(
                    x =>
                    x.IsNewest && !x.IsDeleted &&
                    !allReservations
                    .Any(
                        r =>
                        r.Status != ReservationOrderStatus.Cancelled && r.Table == x && DbFunctions.DiffMinutes(r.ReservationTime, orderDate) < 30));

            return(table);
        }
Example #15
0
 internal OubliMotDePasse Details(string identifiant)
 {
     using (foodtruckEntities db = new foodtruckEntities())
     {
         DateTime maintenant      = DateTime.Now;
         var      oubliMotDePasse = (from u in db.OubliMotDePasse
                                     where u.CodeVerification == identifiant && DbFunctions.DiffMinutes(maintenant, u.DateFinValidite) >= 0
                                     select u).FirstOrDefault();
         return(oubliMotDePasse);
     }
 }