public JsonResult GetUserDataSyncStatus(long userId)
        {
            var dataSyncItems = new List <AppUserDataSync>();
            var email         = UserClaimHelpers.Email(User.Identity);
            var user          = _userRepo.GetAppUserByEmail(email);

            if (user == null)
            {
                throw new Exception("Unable to locate user '" + email + "'!");
            }
            if (!user.id.HasValue)
            {
                user.id = userId;
                _userRepo.UpdateUser(user);
                _userRepo.Base.SaveAll(User);
            }
            var models = _userRepo.GetUserDataSyncStatus(user.AppUserId);

            if (!models.Any(k => k.StartTime.Date == DateTime.UtcNow.Date))
            {
                var newDs = new AppUserDataSync()
                {
                    StartTime = DateTime.UtcNow,
                    AppUserId = user.AppUserId,
                };
                models.Add(newDs);
                _userRepo.AddDataSyncStatus(newDs);
                _userRepo.Base.SaveAll(User);
            }

            var vms = models
                      .OrderByDescending(k => k.StartTime)
                      .Select(k => k.ToViewModel());

            return(Json(vms));
        }
 public void UpdateDataSync(AppUserDataSync dataSyncEntity)
 {
     _context.AppUserDataSyncs.Update(dataSyncEntity);
 }
 public void AddDataSyncStatus(AppUserDataSync newDs)
 {
     _context.AppUserDataSyncs.Add(newDs);
 }