/// <summary> /// Handler for Delete/Move buttons /// </summary> protected void CartItem_Command(object sender, CommandEventArgs e) { var profile = new Data.Profile(); using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(Page.User.Identity.Name); profile.Detach(); } if (!string.IsNullOrEmpty(profile.Username)) { switch (e.CommandName) { case "Del": CartHelper.Remove(profile.WishList, e.CommandArgument.ToString()); break; case "Move": CartHelper.MoveToCart(profile, e.CommandArgument.ToString()); break; } } BindCart(); }
public void CreateProfile() { Stopwatch watch = Stopwatch.StartNew(); var profile = new Profile(); profile.Username = NAME; profile.ApplicationName = PetShopConstants.APPLICATION_NAME; profile.IsAnonymous = false; profile.LastActivityDate = DateTime.Now; profile.LastUpdatedDate = DateTime.Now; try { using (var context = new PetShopDataContext()) { context.Profile.InsertOnSubmit(profile); context.SubmitChanges(); } } catch (Exception ex) { Assert.Fail(ex.Message); } Assert.IsTrue(true); Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }
public static void MoveToCart(Profile profile, string itemId) { var item = profile.WishList.FirstOrDefault(i => i.ItemId == itemId); using (var context = new PetShopDataContext()) { context.Cart.Attach(item); item.IsShoppingCart = true; context.SubmitChanges(); } profile.WishList.Remove(item); profile.ShoppingCart.Add(item); }
/// <summary> /// Constructor with specified initial values. /// </summary> /// <param name="profile">User's Profile</param> public Address(Profile profile) { if (!string.IsNullOrEmpty(profile.Username) && profile.AccountList.Count > 0) { //Just grab the first account. Account account = profile.AccountList[0]; FirstName = account.FirstName; LastName = account.LastName; Address1 = account.Address1; Address2 = account.Address2; City = account.City; State = account.State; Zip = account.Zip; Country = account.Country; Phone = account.Phone; Email = account.Email; } }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { using (var context = new PetShopDataContext()) { string userName = ((System.Web.UI.WebControls.CreateUserWizard)sender).UserName; var profile = context.Profile.GetProfile(userName); if (null == profile) { profile = new Profile(); profile.Username = userName; profile.ApplicationName = ".NET Pet Shop 4.0"; profile.IsAnonymous = false; profile.LastActivityDate = DateTime.Now; profile.LastUpdatedDate = DateTime.Now; context.Profile.InsertOnSubmit(profile); context.SubmitChanges(); } } }
/// <summary> /// Bind controls to profile /// </summary> private void BindUser() { using (var context = new PetShopDataContext()) { var profile = context.Profile.GetProfile(User.Identity.Name); if (string.IsNullOrEmpty(profile.Username)) { profile = new Profile(); profile.Username = User.Identity.Name; profile.ApplicationName = ".NET Pet Shop 4.0"; profile.IsAnonymous = !User.Identity.IsAuthenticated; profile.LastActivityDate = DateTime.Now; profile.LastUpdatedDate = DateTime.Now; context.Profile.InsertOnSubmit(profile); context.SubmitChanges(); } AddressForm.Address = new Address(profile); } }
/// <summary> /// Bind repeater to Cart object in Profile /// </summary> private void BindCart() { var profile = new Data.Profile(); using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(Page.User.Identity.Name); } if (!string.IsNullOrEmpty(profile.Username)) { List<Cart> wishList = profile.WishList; if (wishList.Count > 0) { repWishList.DataSource = wishList; repWishList.DataBind(); } else { repWishList.Visible = false; lblMsg.Text = "Your wish list is empty."; } } }
/// <summary> /// Bind repeater to Cart object in Profile /// </summary> private void BindCart() { var profile = new Data.Profile(); using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(Page.User.Identity.Name); } if (!string.IsNullOrEmpty(profile.Username)) { List <Cart> wishList = profile.WishList; if (wishList.Count > 0) { repWishList.DataSource = wishList; repWishList.DataBind(); } else { repWishList.Visible = false; lblMsg.Text = "Your wish list is empty."; } } }
partial void OnProfileChanging(Profile value);