public void AddFriend(Guid currentUserId, string currentUserEmail, string currentUserName, string friendEmail) { var context = new aspnetdbEntities(); var newFriend = context.Friends.CreateObject(); newFriend.UserId = currentUserId; newFriend.EmailAddress = friendEmail; context.AddToFriends(newFriend); context.SaveChanges(); /*var context = new Code.aspnetdbEntities(); * var newFriend=context.Friends.CreateObject(); * newFriend.UserId = (Guid)Membership.GetUser().ProviderUserKey; * newFriend.EmailAddress = EmailTextBox.Text; * context.Friends.AddObject(newFriend); * context.SaveChanges(); */ var notificationService = new NotificationService(); notificationService.SendNotification(currentUserEmail, currentUserName, friendEmail, context); }
public List <AspNetUser> GetPhBOw(string Owname) //get phonebook { aspnetdbEntities db = new aspnetdbEntities(); List <AspNetUser> selrec = new List <AspNetUser>(); var selectets = db.PrivatePhBs.Where(m => m.OwSAN == Owname); foreach (var sel in selectets) { var srec = db.AspNetUsers.FirstOrDefault(m => m.Id == sel.IdREC); var temp = srec; if (!String.IsNullOrEmpty(sel.Group)) { if (temp != null) { temp.Group = sel.Group; } } if (String.IsNullOrEmpty(sel.Group)) { if (temp != null) { temp.Group = "Группа не назначена"; } } selrec.Add(temp); } return(selrec); }
public void SendNotification(string currentUserEmail, string currentUserName, string friendEmail) { string emailBody = ""; var context = new aspnetdbEntities(); var userService = new UserService(); bool isFriendMember = userService.IsEmailRegistered(friendEmail); if (isFriendMember) { // do they already list current user as one of their friends? var friendUserId = userService.GetUserByEmail(friendEmail).UserId; bool currentUserAlreadyFriend = context.Friends.Any(f => f.UserId == friendUserId && f.EmailAddress == currentUserEmail); if (currentUserAlreadyFriend) { emailBody = String.Format(@"Good News! friend {0} just added you as a friend!", currentUserEmail); } else { emailBody = String.Format(@"{0} added you as a friend on PluralsightBook! Click here to add them as your friend: http://localhost:4927/QuickAddFriend.aspx?email={1}", currentUserName, currentUserEmail); } } else { emailBody = String.Format(@"{0} added you as a friend on PluralsightBook! Click here to register your own account and then add them as your friend: http://localhost:4927/QuickAddFriend.aspx?email={1}", currentUserName, currentUserEmail); } // send email Debug.Print("Sending Email: " + emailBody); }
public Setting Settings_Read() { var db = new aspnetdbEntities(); set = db.Settings.FirstOrDefault(); return(set); }
public JsonResult GetVmRs([DataSourceRequest] DataSourceRequest request) { aspnetdbEntities db = new aspnetdbEntities(); var data = db.AllVmrs.Where(m => m.service_type == "conference"); return(Json(data.ToDataSourceResult(request))); }
public JsonResult GetUsers([DataSourceRequest] DataSourceRequest request) { aspnetdbEntities db = new aspnetdbEntities(); var data = db.AspNetUsers.AsEnumerable(); return(Json(data.ToDataSourceResult(request, o => new { id = o.Id, name = o.DispName }))); }
private IEnumerable <AspNetUser> GetAllPB() { aspnetdbEntities db = new aspnetdbEntities(); var data = db.AspNetUsers.AsEnumerable(); return(data); }
public IEnumerable <Core.Models.Friend> ListFriendsOfUser(Guid userId) { var context = new aspnetdbEntities(); return(context.Friends.Where(f => f.UserId == userId). ToList(). Select(f => Mapper.Map <Core.Models.Friend>(f))); }
public void Delete(int friendId) { var context = new aspnetdbEntities(); var friendToDelete = context.Friends.FirstOrDefault(f => f.Id == friendId); context.Friends.Remove(friendToDelete); context.SaveChanges(); }
public void Save() { using (var context = new aspnetdbEntities()) { context.Friends.Attach(friendEntity); context.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { context = new aspnetdbEntities(); int pID = Convert.ToInt32(Request.QueryString["PID"]); DetailsView1.DataSource = context.Properties.Where(x => x.PropertyID == pID).ToList(); DetailsView1.DataBind(); }
public ActionResult Sett_Read([DataSourceRequest] DataSourceRequest request) { using (var northwind = new aspnetdbEntities()) { IQueryable <Setting> products = northwind.Settings; DataSourceResult result = products.ToDataSourceResult(request); return(Json(result)); } }
public Core.Model.User GetUserByEmail(string email) { var context = new aspnetdbEntities(); return(context.aspnet_Membership .Where(m => m.Email == email) .Select(m => new User()) .FirstOrDefault()); }
public void Create(Guid userId, string emailAddress) { var context = new aspnetdbEntities(); var newFriend = context.Friends.Create(); newFriend.UserId = userId; newFriend.EmailAddress = emailAddress; context.Friends.Add(newFriend); context.SaveChanges(); }
public ActiveRecordFriend(int id) { using (var context = new aspnetdbEntities()) { friendEntity = context.Friends.FirstOrDefault(f => f.Id == id); } if (friendEntity == null) { throw new ApplicationException("Specified friend does not exist " + id); } }
public static ActiveRecordFriend CreateNew(string emailAddress, Guid userId) { using (var context = new aspnetdbEntities()) { var friend = context.Friends.Create(); friend.EmailAddress = emailAddress; friend.UserId = userId; context.Friends.Add(friend); context.SaveChanges(); return(new ActiveRecordFriend(friend.Id)); } }
public IEnumerable <Core.Models.Friend> ListFriendsOfUser(Guid userId) { var context = new aspnetdbEntities(); return(context.Friends .Where(f => f.UserId == userId) .Select(f => new Core.Models.Friend() { Id = f.Id, EmailAddress = f.EmailAddress })); }
public void CanCreateNewFriend() { Guid testUserId; using (var context = new aspnetdbEntities()) { testUserId = context.aspnet_Membership.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); Assert.IsNotNull(friend); }
public void AddFriend(Guid currentUserId, string currentUserEmail, string currentUserName, string friendEmail) { var context = new aspnetdbEntities(); var newFriend = context.Friends.Create(); newFriend.UserId = currentUserId; newFriend.EmailAddress = friendEmail; context.Friends.Add(newFriend); context.SaveChanges(); var notificationService = new NotificationService(); notificationService.SendNotification(currentUserEmail, currentUserName, friendEmail); }
public User GetUserByEmail(string email) { var context = new aspnetdbEntities(); return(context.aspnet_Membership. Where(m => m.Email == email). Select(m => new User() { UserId = m.UserId, EmailAddress = m.Email }). FirstOrDefault()); }
public void CompareUsers(List <ApplicationUser> adusList) { var db = new aspnetdbEntities(); var temp_list = new List <string>(); var id_list = new List <string>(); List <ApplicationUser> allr = new List <ApplicationUser>(); var NameQuery = from samaccountname in db.AspNetUsers select samaccountname; if (NameQuery != null) { foreach (var customer in NameQuery) { if ((!adusList.Exists(x => x.Sammaccount == customer.Sammaccount) /*&& !customer.location*/)) { temp_list.Add(customer.Sammaccount); id_list.Add(customer.Id); } } foreach (var stroke in temp_list) { var deleteUsers = from samaccountname in db.AspNetUsers where samaccountname.Sammaccount == stroke select samaccountname; } //foreach (var ids in id_list) //{ // var deleteRecs = // from Id in db.PrivatePhB // where Id.IdREC == ids // select Id; // db.PrivatePhB.Remove(deleteRecs.First()); //} //db.SaveChanges(); } foreach (var adus in adusList) { if (!NameQuery.AsEnumerable().ToList().Exists(x => x.Sammaccount == adus.Sammaccount)) { } } foreach (var temp in temp_list) { Debug.WriteLine(temp); } }
public ActionResult Control(string confname, string dispname) { aspnetdbEntities db = new aspnetdbEntities(); var curvmr = db.AllVmrs.FirstOrDefault(v => v.name == confname); var curalias = db.VmrAliases.FirstOrDefault(v => v.vmid == curvmr.Id); if (curvmr != null) { ViewData["dispnm"] = dispname; ViewData["pinc"] = curvmr.pin; ViewData["confnm"] = curalias.alias; } return(View()); }
public void EmailDomainReturnedCorrectly() { Guid testUserId; using (var context = new aspnetdbEntities()) { testUserId = context.aspnet_Membership.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); var domain = friend.EmailDomain; Assert.AreEqual("foo.com", domain); }
public void ListFriendsUsingMapper() { var mappingFriendRepository = new MappingFriendRepository(); var testUserId = Guid.Empty; using (var context = new aspnetdbEntities()) { testUserId = context.aspnet_Membership.FirstOrDefault().UserId; } var result = mappingFriendRepository.ListFriendsOfUser(testUserId); Assert.IsInstanceOfType(result.FirstOrDefault(), typeof(Core.Models.Friend)); }
public void AddRecord() { var context = new aspnetdbEntities(); var testUser = context.aspnet_Membership.First(); var friendRepository = new EfFriendRepository(); var testFreindEmail = Guid.NewGuid().ToString(); friendRepository.Create(testUser.UserId, testFreindEmail); bool friendExists = context.Friends.Any(f => f.UserId == testUser.UserId && f.EmailAddress == testFreindEmail); Assert.IsTrue(friendExists); context.Friends.Remove(context.Friends.FirstOrDefault(f => f.UserId == testUser.UserId && f.EmailAddress == testFreindEmail)); context.SaveChanges(); }
//Get Personal Phonebook public ActionResult Phonebook_Ajax() { aspnetdbEntities dbs = new aspnetdbEntities(); ApplicationDbContext db = new ApplicationDbContext(); List <ApplicationUser> selrec = new List <ApplicationUser>(); IEnumerable <PrivatePhB> selectets = (dbs.PrivatePhBs.Where(m => m.OwSAN == User.Identity.Name)); foreach (var sel in selectets) { Debug.WriteLine((db.Users.FirstOrDefault(m => m.Id == sel.IdREC).DispName)); selrec.Add(db.Users.FirstOrDefault(m => m.Id == sel.IdREC)); } return(Json(new { data = selrec, }, JsonRequestBehavior.AllowGet)); }
public void CanSaveChangesToFriend() { Guid testUserId; using (var context = new aspnetdbEntities()) { testUserId = context.aspnet_Membership.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); var secondFriend = new ActiveRecordFriend(friend.Id); secondFriend.EmailAddress = "updated"; secondFriend.Save(); var thirdFriend = new ActiveRecordFriend(friend.Id); Assert.AreEqual(friend.EmailAddress, thirdFriend.EmailAddress); }
public void Button_Click() { // read some values from UI elements Guid currentUserId = Guid.NewGuid(); // (Guid)Membership.GetUser().ProviderUserKey; string friendEmail = ""; // EmailTextBox.Text; // maybe do some validation // save stuff to the database using (var context = new aspnetdbEntities()) { var friend = context.Friends.Create(); friend.EmailAddress = friendEmail; friend.UserId = currentUserId; context.Friends.Add(friend); context.SaveChanges(); } // maybe update a label or redirect }
public bool addUserToPrivat(string Owner, string IdRec, string Group) { aspnetdbEntities db = new aspnetdbEntities(); PrivatePhB newrecpriv = new PrivatePhB(); newrecpriv.OwSAN = Owner; newrecpriv.IdREC = IdRec; newrecpriv.Group = Group; db.PrivatePhBs.AddOrUpdate(newrecpriv); try { db.SaveChanges(); return(true); } catch (Exception ex) { Debug.WriteLine(ex.InnerException); return(false); } }
public void AddRecordTx() { Guid testUserId; using (var context = new aspnetdbEntities()) { testUserId = context.aspnet_Membership.First().UserId; } var friendRepository = new EfFriendRepository(); var testEmail = Guid.NewGuid().ToString(); friendRepository.Create(testUserId, testEmail); using (var context = new aspnetdbEntities()) { bool friendExists = context.Friends.Any(f => f.UserId == testUserId && f.EmailAddress == testEmail); Assert.IsTrue(friendExists); //context.DeleteObject(context.Friends.FirstOrDefault(f => f.UserId == testUserId && f.EmailAddress == testEmail)); //context.SaveChanges(); } }