public ActionResult Index() { //fetch page info var context = new DataContext(); var fbPageRepos = new EFDataRepository <FacebookPage>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var pages = fbPageRepos.Query(u => u.UserId == SessionManager.User.Id); var pageModels = pages.IsNullOrEmpty() ? new List <FacebookPageModel>() : pages.Select( p => (FacebookPageModel) AutoMapper.Mapper.Map(p, typeof(FacebookPage), typeof(FacebookPageModel))).ToList(); var model = new UserSettingsPageModel(SessionManager.UserSettings) { FacebookPageDDL = !SessionManager.IsLoggedIntoFacebook || pageModels.IsNullOrEmpty() ? new Dictionary <long, string>() : pageModels.ToDictionary(p => Int64.Parse(p.PageId), p => p.Title) }; return(View(model)); }
public void Test_Context_Read() { var dbContext = new Service.Shared.Data.DataContext(true); //var x = (dbContext.Queries as IQueryable<IDataEntity>).ToList(); IDataRepository <IDataEntity> readRepos = new EFDataRepository <Query>(dbContext) { Properties = new DataRepositoryProperties() { ExcludeDeleted = true, IncludeRelated = true, NavigationProperties = new List <System.Linq.Expressions.Expression <Func <Domain.Query, object> > >() { { q => q.QueryProjections } } } }; //readRepos.LimitTotal = true; //readRepos.StartIndex = 0; //readRepos.TotalRows = 5; var q1 = readRepos.GetAll().ToList(); var fixedQ = DataHelpers.FixNavigationProperties(readRepos.Properties, q1[0]); var q2 = readRepos.Query(q => (q as Query).CategoryId == 1).ToList(); }
public static IIntelliFlowItem Create(Domain.IntelliFlowItem item, IDataContext context) { var fac = _itemFac[(Enums.IntelliFlowItemType)item.ItemTypeId]; var newItem = fac.Create(item.ItemTypeId); IDataRepository <Domain.IntelliFlowItem> itemRepos = new EFDataRepository <Domain.IntelliFlowItem>(context); IDataRepository <Domain.Expression> exprRepos = new EFDataRepository <Domain.Expression>(context); var childItems = itemRepos.Query(x => x.ParentItemId == (long)item.Id).ToArray(); if (!childItems.IsNullOrEmpty()) { var childItemList = new List <IIntelliFlowItem>(); foreach (var child in childItems) { var newChild = _Create(child, context, true); childItemList.Add(newChild); } newItem.Children = new IntelliFlowIterator <IIntelliFlowItem>(childItemList.ToArray()); } if (item.ParentItemId.HasValue) { var parent = itemRepos.Get(item.ParentItemId.Value); var newParent = _Create(parent, context, false); newItem.Parent = newParent; } if (!item.Data.IsNullOrEmpty()) { newItem.Input.Data = BinarySerializer.Deserialize((NEMILTEC.Shared.Enums.Data.DataType)item.DataTypeId, item.Data); } var itemExp = exprRepos.Query(x => x.ParentItemId == (long)item.Id).ToArray(); if (!itemExp.IsNullOrEmpty()) { var paramList = new List <IntelliFlowItemInputParameter>(); foreach (var exp in itemExp) { var param = new IntelliFlowItemInputParameter(); var newExp = ExpressionFactory.Create(exp, context); if (newExp is ValueExpression) { var valExp = newExp as ValueExpression; param.Value = valExp.Value; } param.Expression = newExp; paramList.Add(param); } newItem.Input.Parameters = paramList; } return(newItem); }
public ActionResult Output(long queryId) { var context = new DataContext(false); var queryOutputRepos = new EFDataRepository <Domain.QueryOutput>(context); var output = queryOutputRepos.Query(o => o.QueryId == queryId).Last(); var dt = BinarySerializer.Deserialize <DataTable>(output.Data); return(View(new QueryOutputModel() { Data = dt })); }
public ContentResult Save(string settingsJSON) { //var model = new InstantArticlesPageModel() //{ // InstantArticles = _GetViewModels() //}; UserSettingModel model; try { model = JSONSerializer.Deserialize <UserSettingModel>(settingsJSON); var context = new DataContext(); var userSettingRepos = new EFDataRepository <UserSetting>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var userSettings = (UserSetting)AutoMapper.Mapper.Map(model, typeof(UserSettingModel), typeof(UserSetting)); userSettingRepos.AddOrUpdate((IDataEntity)userSettings); SessionManager.UserSettings = model; var fbPageRepos = new EFDataRepository <FacebookPage>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var page = fbPageRepos.Query(u => u.UserId == SessionManager.User.Id).FirstOrDefault(); SessionManager.FacebookPage = (FacebookPageModel)AutoMapper.Mapper.Map(page, typeof(FacebookPage), typeof(FacebookPageModel)); } catch (Exception ex) { return(_ConvertToJSON(new { Success = false })); } return(_ConvertToJSON(new { Success = true, Settings = model })); }
public async Task <ContentResult> CreateAdmin() { if (UserManager.FindByName("admin") == null) { var user = new ApplicationUser { UserName = Settings.AdminUser, Email = Settings.AdminEmail }; var result = await UserManager.CreateAsync(user, Settings.AdminPassword); if (result.Succeeded) { result = UserManager.AddToRole(user.Id, "Admin"); var context = new DataContext(); var userRepos = new EFDataRepository <User>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var savedUser = userRepos.Query(u => u.UserName == user.UserName).FirstOrDefault(); if (savedUser == null) { var newUser = new User() { UserName = Settings.AdminUser, Email = Settings.AdminEmail, Password = Settings.AdminPassword, FirstName = Settings.AdminFirstName, LastName = Settings.AdminLastName, UserId = user.Id }; userRepos.AddOrUpdate(newUser); } return(Content(String.Format("Successfully created admin user\n\rUser Id: {0}.", user.Id))); } } return(Content(String.Format("Error creating admin user account."))); }
public static IIntelliFlow Create(Domain.IntelliFlow data, IDataContext context) { IDataRepository <Domain.IntelliFlowItem> itemRepos = new EFDataRepository <Domain.IntelliFlowItem>(context); var items = itemRepos.Query(x => x.IntelliFlowId == (long)data.Id).ToArray(); var intFlow = new IntelliFlow(); if (!items.IsNullOrEmpty()) { var itemList = new List <IIntelliFlowItem>(); foreach (var item in items) { var newItem = Create(item, context); itemList.Add(newItem); } intFlow.Items = new IntelliFlowIterator <IIntelliFlowItem>(itemList.ToArray()); } return(intFlow); }
public static IDataExpression Create(Domain.Expression exp, IDataContext context) { IDataRepository<Domain.Expression> exprRepos = new EFDataRepository<Domain.Expression>(context); var newExp = ExpressionFactory.Create((ExpressionType)exp.ExpressionTypeId); IDataExpression outExp = newExp; if (outExp is ICompositeExpression) { var compExp = newExp as ICompositeExpression; var childExp = exprRepos.Query(x => x.ParentExpressionId == (long)exp.Id).ToArray(); if (!childExp.IsNullOrEmpty()) { var childExpList = new List<IDataExpression>(); foreach (var child in childExp) { var newChild = _Create(child, context); childExpList.Add(newChild); } compExp.Expressions = childExpList; } outExp = compExp; } if (outExp is ValueExpression) { var valExp = outExp as ValueExpression; valExp.Value = BinarySerializer.Deserialize((NEMILTEC.Shared.Enums.Data.DataType)exp.DataTypeId, exp.Value); outExp = valExp; } return outExp; }
public static bool UpdateFacebookSessionInfo(string accessToken, string userId) { try { SessionManager.FacebookUserAccessToken = accessToken; SessionManager.FacebookUserId = userId; //get/save pages info to db var fb = new FacebookClient(accessToken); dynamic result = fb.Get($"{userId}/accounts"); var pageList = new List <FacebookPageModel>(); foreach (dynamic page in result.data) { pageList.Add(new FacebookPageModel() { PageId = page.id, Title = page.name, AccessToken = page.access_token, FacebookUserId = userId, UserId = SessionManager.User.Id }); } var db = new DataContext(); var fbPageRepos = new EFDataRepository <FacebookPage>(db) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = true }; //remove old pages var oldIds = fbPageRepos.Query(p => p.UserId == SessionManager.User.Id).Select(p => p.Id).ToList(); fbPageRepos.Remove(oldIds); //add new fbPageRepos.AddOrUpdate( pageList.Select( p => (FacebookPage) AutoMapper.Mapper.Map(p, typeof(FacebookPageModel), typeof(FacebookPage))).Cast <IDataEntity>()); //get/save app access token to session fb = new FacebookClient(accessToken); dynamic parameters = new ExpandoObject(); parameters.grant_type = "fb_exchange_token"; parameters.client_id = Settings.FacebookAppId; parameters.client_secret = Settings.FacebookAppSecret; parameters.fb_exchange_token = accessToken; result = fb.Get($"oauth/access_token", parameters); SessionManager.FacebookAppAccessToken = result.access_token; } catch (Exception ex) { return(false); } return(true); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { ViewBag.HideNavBars = true; if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true ApplicationUser user = UserManager.FindByEmail(model.Email); var result = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: //save user info var context = new DataContext(); var userRepos = new EFDataRepository <User>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var savedUser = userRepos.Query(u => u.UserName == user.UserName).FirstOrDefault(); if (savedUser != null) { SessionManager.User = (UserModel)AutoMapper.Mapper.Map(savedUser, typeof(User), typeof(UserModel)); } //create/retrieve user settings var userSettingRepos = new EFDataRepository <UserSetting>(context) { ExcludeDeleted = true, IncludeRelated = true, SaveChanges = true, DeletePermanent = false }; var savedUserSettings = userSettingRepos.Query(u => u.UserId == savedUser.Id).FirstOrDefault(); if (savedUserSettings == null) { var newUserSettings = new UserSetting() { UserId = savedUser.Id, }; SessionManager.UserSettings = (UserSettingModel) AutoMapper.Mapper.Map(newUserSettings, typeof(UserSetting), typeof(UserSettingModel)); userSettingRepos.AddOrUpdate(newUserSettings); } else { SessionManager.UserSettings = (UserSettingModel) AutoMapper.Mapper.Map(savedUserSettings, typeof(UserSetting), typeof(UserSettingModel)); } return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt. Email/Password incorrect or missing."); return(View(model)); } }