Exemple #1
0
        public void Syncs()
        {
            IEnumerable <ApplicationUser> FromList;
            IEnumerable <ApplicationUser> ToList;

            int AppId = (int)System.Web.HttpContext.Current.Session["ApplicationId"];

            using (LoginApplicationDbContext dbContext = new LoginApplicationDbContext())
            {
                FromList = dbContext.Database.SqlQuery <ApplicationUser>(" SELECT A.* FROM AspNetUsers A JOIN UserApplications UA ON A.Id = UA.UserId WHERE UA.ApplicationId=" + AppId).ToList();
            }


            ToList = ((ApplicationDbContext)_context).Database.SqlQuery <ApplicationUser>(" SELECT * FROM Web.Users ").ToList();


            IEnumerable <ApplicationUser> PendingToUpdate;

            PendingToUpdate = from p in FromList
                              join t in ToList on p.Id equals t.Id into Left
                              from lef in Left.DefaultIfEmpty()
                              where lef == null
                              select p;

            foreach (var item in PendingToUpdate)
            {
                ApplicationUser NewRec = new ApplicationUser();
                NewRec             = item;
                NewRec.ObjectState = Model.ObjectState.Added;
                ((ApplicationDbContext)_context).Users.Add(NewRec);
            }

            _context.SaveChanges();
        }
Exemple #2
0
        public int GetNotificationCount(string UserName)
        {
            var Today = DateTime.Now.Date;

            using (LoginApplicationDbContext ldb = new LoginApplicationDbContext())
            {
                var NotificationCount = (from p in ldb.NotificationUser
                                         join t in ldb.Notification on p.NotificationId equals t.NotificationId
                                         where p.UserName == UserName && t.ExpiryDate >= Today && t.SeenDate == null && t.ReadDate == null
                                         select p).Count();

                return(NotificationCount);
            }
        }