public static Task UpdateUserAsync(AuthenticationResult result) { var fb = GetUserFacebookClient(); return Task.Run(() => { Logger.InfoFormat("Performing update of user {0}", result.UserName); try { using (var db = new ShoppingListDbContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == result.UserName.ToLower()); if (user != null) { dynamic picture = fb.Get("me", new { fields = "picture", type = "square" }); user.AccessToken = result.ExtraData.ReadField(Oauth.FieldNames.AccessToken); user.Name = result.ExtraData.ReadField(Oauth.FieldNames.Name); user.Gender = result.ExtraData.ReadField(Oauth.FieldNames.Gender); user.PictureUrl = picture.picture.data.url; db.SaveChanges(); } } } catch (Exception ex) { Logger.Error(String.Format("Update of user {0} failed.", result.UserName), ex); } }); }
private static string ReadAccessTokenFromDb() { var db = new ShoppingListDbContext(); var user = db.UserProfiles.FirstOrDefault(userProfile => userProfile.UserName.ToLower() == Thread.CurrentPrincipal.Identity.Name.ToLower()); return(user != null ? user.AccessToken : null); }
public ItemViewModel GetItemByID(int?id) { Item entity; using (var ctx = new ShoppingListDbContext()) { entity = ctx.Items.SingleOrDefault(e => e.ID == id); } if (entity != null) { return new ItemViewModel { ID = entity.ID, ShoppingListID = entity.ShoppingListID, Content = entity.Content, IsChecked = entity.IsChecked, Priority = entity.Priority, CreatedUtc = entity.CreatedUtc, ModifiedUtc = entity.ModifiedUtc } } ; else { return(null); } }
public static Task UpdateUserAsync(AuthenticationResult result) { var fb = GetUserFacebookClient(); return(Task.Run(() => { Logger.InfoFormat("Performing update of user {0}", result.UserName); try { using (var db = new ShoppingListDbContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == result.UserName.ToLower()); if (user != null) { dynamic picture = fb.Get("me", new { fields = "picture", type = "square" }); user.AccessToken = result.ExtraData.ReadField(Oauth.FieldNames.AccessToken); user.Name = result.ExtraData.ReadField(Oauth.FieldNames.Name); user.Gender = result.ExtraData.ReadField(Oauth.FieldNames.Gender); user.PictureUrl = picture.picture.data.url; db.SaveChanges(); } } } catch (Exception ex) { Logger.Error(String.Format("Update of user {0} failed.", result.UserName), ex); } })); }
public string GetShoppingListName(int id) { using (var ctx = new ShoppingListDbContext()) { return(ctx.ShoppingLists.Where(e => e.ID == id).SingleOrDefault().Name); } }
public ShoppingListViewModel GetListByID(int?id) { ShoppingList entity; using (var ctx = new ShoppingListDbContext()) { entity = ctx.ShoppingLists.SingleOrDefault(e => e.ID == id); } if (entity != null) { return new ShoppingListViewModel { ID = entity.ID, Name = entity.Name, Group = entity.Group, Color = entity.Color, CreatedUtc = entity.CreatedUtc, ModifiedUtc = entity.ModifieddUtc } } ; else { return(null); } }
public SqlShoppingListRepo(ShoppingListDbContext context, GroceryPredictionPool predictionEnginePool, IUserPasswordSalt salt) { _context = context; _waypointsRepo = new SqlWaypointsRepo(_context); _predictionEnginePool = predictionEnginePool; _salt = salt; }
public bool Delete(int itemId) { var dbContext = new ShoppingListDbContext(); var itemSqlDatabase = new ItemSqlStorage(dbContext); return(new Item().DeleteItem(itemId, itemSqlDatabase)); }
public bool Delete(int shoppingItemId) { var dbContext = new ShoppingListDbContext(); var shoppingItemSqlStorage = new ShoppingItemSqlStorage(dbContext); return(new ShoppingItem().DeleteItem(shoppingItemId, shoppingItemSqlStorage)); }
public bool Delete(int pictureId) { var dbContext = new ShoppingListDbContext(); var pictureSqlStorage = new PictureSqlStorage(dbContext); return(new Picture().DeleteItem(pictureId, pictureSqlStorage)); }
public bool Edit(int itemId, string noteBody) { using (var ctx = new ShoppingListDbContext()) { var command = @"UPDATE Note SET Body = {0}, ModifiedUtc = {1} WHERE ItemId = {2}"; var result = ctx.Database.ExecuteSqlCommand(command, noteBody, DateTimeOffset.UtcNow, itemId); return(result == 1); } }
public bool Create(int itemId, string noteBody) { using (var ctx = new ShoppingListDbContext()) { var command = @"INSERT INTO Note (ItemId, Body, CreatedUtc) VALUES({0}, {1}, {2})"; var result = ctx.Database.ExecuteSqlCommand(command, itemId, noteBody, DateTimeOffset.UtcNow); return(result == 1); } }
public IEnumerable <ShoppingListViewModel> GetList() { using (var ctx = new ShoppingListDbContext()) { return(ctx.ShoppingLists.Where(e => e.UserID == _userID).Select( e => new ShoppingListViewModel { ID = e.ID, Name = e.Name, Color = e.Color, Group = e.Group, CreatedUtc = e.CreatedUtc, ModifiedUtc = e.ModifieddUtc } ).ToArray()); } }
public Item AddUpdate(Item item) { var dbContext = new ShoppingListDbContext(); var itemSqlDatabase = new ItemSqlStorage(dbContext); var itemToUpdate = itemSqlDatabase.GetById(item.Id); itemToUpdate.AddUpdateItem(item, itemSqlDatabase); return(itemToUpdate); }
public ShoppingItem AddUpdate(ShoppingItem shoppingItem) { var dbContext = new ShoppingListDbContext(); var shoppingItemSqlStorage = new ShoppingItemSqlStorage(dbContext); var itemToUpdate = shoppingItemSqlStorage.GetById(shoppingItem.Id); itemToUpdate.AddUpdateItem(shoppingItem, shoppingItemSqlStorage); return(itemToUpdate); }
public Picture AddUpdate(Picture picture) { var dbContext = new ShoppingListDbContext(); var pictureSqlStorage = new PictureSqlStorage(dbContext); var pictureToUpdate = pictureSqlStorage.GetById(picture.Id); pictureToUpdate.AddUpdateItem(picture, pictureSqlStorage); return(pictureToUpdate); }
public ShoppingEvent AddUpdate(ShoppingEvent shoppingEvent) { var dbContext = new ShoppingListDbContext(); var shoppingEventSqlStorage = new ShoppingEventSqlStorage(dbContext); var itemToUpdate = shoppingEventSqlStorage.GetById(shoppingEvent.Id); itemToUpdate.AddUpdateItem(shoppingEvent, shoppingEventSqlStorage); return(itemToUpdate); }
public IEnumerable <ItemViewModel> GetItemsByShoppingListID(int?id) { using (var ctx = new ShoppingListDbContext()) { string query = "SELECT * FROM Item WHERE ShoppingListID = @p0"; return(ctx.Items.SqlQuery(query, id).Select( e => new ItemViewModel { ID = e.ID, ShoppingListID = id.Value, Priority = e.Priority, Content = e.Content, IsChecked = e.IsChecked, CreatedUtc = e.CreatedUtc, ModifiedUtc = e.ModifiedUtc } ).ToArray()); } }
public bool DeleteNote(int?id) { using (var ctx = new ShoppingListDbContext()) { var entity = ctx.Notes.SingleOrDefault(e => e.ItemId == id); // TODO: Handle note not found ctx.Notes.Remove(entity); return(ctx.SaveChanges() == 1); } }
public bool UpdateList(ShoppingListViewModel vm) { using (var ctx = new ShoppingListDbContext()) { var entity = ctx.ShoppingLists.SingleOrDefault(e => e.ID == vm.ID); entity.Name = vm.Name; entity.Color = vm.Color; entity.Group = (vm.Group == null || vm.Group == "") ? "General" : vm.Group; entity.ModifieddUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public bool DeleteList(int?id) { using (var ctx = new ShoppingListDbContext()) { //ctx.Database.ExecuteSqlCommand($"DELETE FROM Item WHERE ShoppingListID = {id}"); var entity = ctx.ShoppingLists.SingleOrDefault(e => e.ID == id); // TODO: Handle note not found ctx.ShoppingLists.Remove(entity); return(ctx.SaveChanges() == 1); } }
public void DeleteAllItems(int?shoppingListID, string path) { using (var ctx = new ShoppingListDbContext()) { //ctx.Database.ExecuteSqlCommand($"DELETE FROM Item WHERE ShoppingListID = {shoppingListID}"); var items = ctx.Items.Where(item => item.ShoppingListID == shoppingListID); foreach (var item in items) { ctx.Items.Remove(item); DeleteFile(path + "\\" + item.ID + ".jpg"); } ctx.SaveChanges(); } }
public int[] UpdateItem(ItemViewModel vm) { using (var ctx = new ShoppingListDbContext()) { var entity = ctx.Items.SingleOrDefault(e => e.ID == vm.ID); entity.Content = vm.Content; entity.Priority = vm.Priority; entity.IsChecked = vm.IsChecked.Value; entity.ModifiedUtc = DateTimeOffset.UtcNow; int[] result = new int[] { ctx.SaveChanges(), entity.ID }; return(result); } }
public bool CreateList(ShoppingListViewModel vm) { using (var ctx = new ShoppingListDbContext()) { var entity = new ShoppingList { UserID = _userID, Name = vm.Name, Color = vm.Color, Group = (vm.Group == null || vm.Group == "") ? "General" : vm.Group, CreatedUtc = DateTimeOffset.UtcNow, }; ctx.ShoppingLists.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new ShoppingListDbContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public int[] CreateItem(ItemViewModel vm, int shoppingListId) { using (var ctx = new ShoppingListDbContext()) { var entity = new Item { ShoppingListID = shoppingListId, Content = vm.Content, Priority = vm.Priority, IsChecked = vm.IsChecked.Value, CreatedUtc = DateTimeOffset.UtcNow, }; ctx.Items.Add(entity); int[] result = new int[] { ctx.SaveChanges(), entity.ID }; return(result); } }
public SqlShoppingListRepoExampleData(ShoppingListDbContext context, PredictionEnginePool <GroceryData, GroceryItemPrediction> predictionEnginePool, IUserPasswordSalt salt) : base(context, predictionEnginePool, salt) { if (context.ShopWaypointsEntities.ToList().Count == 0) { var userCreateDto = new UserCreateDto("user", "password"); var userEntity = ToUserEntity(userCreateDto); context.UserEntities.Add(userEntity); SaveChanges(); context.ShopWaypointsEntities.Add(new ShopWaypointsEntity { Id = 0, Name = "big-market", ShoppingListEntities = new List <ShoppingListEntity>(), ShopWaypointsReadDtoJson = JsonSerializer.Serialize(WaypointsRepoHardcoded.HardcodedWaypoints) }); SaveChanges();
public static void RegisterAuth() { var db = new ShoppingListDbContext(); db.Database.Initialize(false); WebSecurity.InitializeDatabaseConnection("DefaultConnection", typeof(UserProfile).Name, "UserId", "UserName", autoCreateTables: true); // To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter, // you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166 //OAuthWebSecurity.RegisterMicrosoftClient( // clientId: "", // clientSecret: ""); //OAuthWebSecurity.RegisterTwitterClient( // consumerKey: "", // consumerSecret: ""); OAuthWebSecurity.RegisterFacebookClient( appId: Oauth.FbAppId, appSecret: Oauth.FbAppSecret); OAuthWebSecurity.RegisterGoogleClient(); }
public NoteViewModel GetNoteByItemID(int?id) { Note entity; using (var ctx = new ShoppingListDbContext()) { entity = ctx.Notes.SingleOrDefault(e => e.ItemId == id); } if (entity != null) { return new NoteViewModel { ItemId = entity.ItemId, Body = entity.Body, CreatedUtc = entity.CreatedUtc, ModifiedUtc = entity.ModifiedUtc } } ; else { return(null); } }
public ConsumerRepository(ShoppingListDbContext shoppingListDbContext) { _shoppingListDbContext = shoppingListDbContext; }
public ShoppingListNotificationService(IHubContext <ShoppingListHub> hub, ShoppingListDbContext db) { this.hub = hub; this.db = db; }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { // Insert a new user into the database using (var db = new ShoppingListDbContext()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return View(model); }
private static string ReadAccessTokenFromDb() { var db = new ShoppingListDbContext(); var user = db.UserProfiles.FirstOrDefault(userProfile => userProfile.UserName.ToLower() == Thread.CurrentPrincipal.Identity.Name.ToLower()); return user != null ? user.AccessToken : null; }