Esempio n. 1
0
    /// <summary>
    /// Event handler for the gvPost_RowCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void gvPost_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "removeFavorite")
        {
            // Retrieve index of row generating event
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the id of the object bound to row
            int id = Convert.ToInt32(gvPost.DataKeys[index].Values["Id"].ToString());

            // Create a temp post with same id
            TravelPost post = new TravelPost();
            post.Id = id;

            // Remove from session
            FavoritesSessionFacade.Remove(post);

            // Display message
            if (FavoritesSessionFacade.PostCount() > 0)
            {
                lbPostErrorMessage.Text = "";
            }
            else
            {
                lbPostErrorMessage.Text = "No favorited posts.";
            }

            // Rebind
            gvPost.DataSource = FavoritesSessionFacade.PostCollection;
            gvPost.DataBind();
        }
    }
 public void AddTravelBlogPost(TravelPost TPost)
 {
     if (TPost.TravelId == Guid.Empty)
     {
         TPost.TravelId = Guid.NewGuid();
     }
     _ctx.TravelPosts.Add(TPost);
 }
        public async Task <IActionResult> OnGetAsync(Guid TravelId)
        {
            TravelPost = await _repo.GetTravelPostForUser(TravelId);

            if (TravelPost == null)
            {
                return(RedirectToPage("Index"));
            }

            return(Page());
        }
        /// <summary>
        /// Removes a post
        /// </summary>
        /// <param name="post">a post</param>
        /// <returns></returns>
        public static bool Remove(TravelPost post)
        {
            bool isRemoved = false;

            if (IsFavoritesExist())
            {
                Favorites temp = RetrieveFavoritesFromSession();
                isRemoved = temp.Remove(post);
                SendFavoritesToSession(temp);
            }
            return(isRemoved);
        }
        /// <summary>
        /// Adds a post to favorites
        /// </summary>
        /// <param name="post">a post</param>
        /// <returns>true/false value indicating if added</returns>
        public static bool Add(TravelPost post)
        {
            bool      isAdded = false;
            Favorites temp    = RetrieveFavoritesFromSession();

            if (!temp.IsExist(post))
            {
                temp.Add(post);
                SendFavoritesToSession(temp);
                isAdded = false;
            }
            return(isAdded);
        }
Esempio n. 6
0
    /// <summary>
    /// Event handler for the lvPostData_ItemCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void lvPostData_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        // Retrieve item which raised item command event
        ListViewItem item = (ListViewItem)e.Item;

        // Retrieve item index
        int index = Convert.ToInt32(item.DisplayIndex);

        // Initialize object
        TravelPost post = new TravelPost();

        post.Id    = Convert.ToInt32(lvPostData.DataKeys[index].Values["Id"]);;
        post.Title = lvPostData.DataKeys[index].Values["Title"].ToString();;

        // Save to session (favorites)
        FavoritesSessionFacade.Add(post);

        // Redirect to favorites page upon redirect
        Response.Redirect("./Favorites.aspx");
    }
Esempio n. 7
0
    /// <summary>
    /// Event handler for the gvPost_RowCommand event
    /// </summary>
    /// <param name="sender">a sender</param>
    /// <param name="e">a e</param>
    protected void gvPost_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "addFavorite")
        {
            // Retrieve index of row generating event
            int index = Convert.ToInt32(e.CommandArgument);

            // Retrieve the id of the object bound to row
            int id = Convert.ToInt32(gvPost.DataKeys[index].Values["Id"].ToString());

            // Initialize object
            TravelPost post = new TravelPost();
            post.Id    = id;
            post.Title = gvPost.DataKeys[index].Values["Title"].ToString();

            // Add to session
            FavoritesSessionFacade.Add(post);

            // Redirect to favorites page
            Response.Redirect("./Favorites.aspx");
        }
    }
Esempio n. 8
0
        public async Task Seed()
        {
            _ctx.Database.EnsureCreated();

            var user = await _userManager.FindByEmailAsync("*****@*****.**");

            var user1 = await _userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new User()
                {
                    FirstName = "Urgen",
                    LastName  = "Dorjee",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };

                user1 = new User()
                {
                    FirstName = "Kalsang",
                    LastName  = "Nyima",
                    UserName  = "******",
                    Email     = "*****@*****.**"
                };
                var result1 = await _userManager.CreateAsync(user1, "Passw0rd!");

                var result = await _userManager.CreateAsync(user, "Passw0rd!");

                if (result1 != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create a default user");
                }

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create a default user");
                }
            }
            if (!_ctx.TechPosts.Any())
            {
                var post = new TechPost()
                {
                    Title           = "Asp.Net Core 2.1 Road Map",
                    Description     = "Microsoft started to ship Asp.Net way back in early 2000 and since then it has been matured quite significantly,it has not much room left to ramp up, therefore the have started to build Asp.Net core from the scratch",
                    PostCreatedDate = DateTime.Now,
                    User            = user
                };
                var post1 = new TechPost()
                {
                    Title           = "MS Build 2018 Redmond Washington",
                    Description     = "Microsoft instroduced Signal R in Asp.Net Core 2.1",
                    PostCreatedDate = DateTime.Now,
                    User            = user,
                };
                var post2 = new TechPost()
                {
                    Title           = "WASM with Blazor",
                    Description     = "It is a great opportunity to a new developer, who can learn new technology that Microsoft come up with.",
                    PostCreatedDate = DateTime.Now,
                    User            = user1
                };
                _ctx.TechPosts.AddRange(post);
                _ctx.TechPosts.AddRange(post1);
                _ctx.TechPosts.AddRange(post2);


                _ctx.SaveChanges();
            }

            if (!_ctx.TravelPosts.Any())
            {
                var travel = new TravelPost()
                {
                    Title           = "Ravangla Road Trip 2018",
                    Description     = "I have been to this place many times since it is my home town, however i have been moved to different place now but what used to be look and feel of this place has been completely overhaul and sometimes feel that I find myself in different place",
                    PostCreatedDate = DateTime.Now,
                    User            = user
                };

                var travel1 = new TravelPost()
                {
                    Title           = "His Holiness Birthday Celebration",
                    Description     = "It is a great pride and auspicious occasion that Tibetan all over the world Celebrate the living embodiment of Avalokiteshwara HH the Dalai Lama birthday, We all tibetan feel undue of his relentless,tireless effort to keep the flame of tibet independence around the world arena.The man of peace is not only love by Tibetan but by most of the countries",
                    PostCreatedDate = DateTime.Now,
                    User            = user1
                };
                _ctx.TravelPosts.AddRange(travel);
                _ctx.TravelPosts.AddRange(travel1);
                _ctx.SaveChanges();
            }
        }
 public void UpdateTravelPostForUser(TravelPost TPost)
 {
     //no code in this implementation..
 }
 public void DeleteTravelPost(TravelPost TPost)
 {
     _ctx.TravelPosts.Remove(TPost);
 }
Esempio n. 11
0
 /// <summary>
 /// Checks to see if post exists in internal collection
 /// </summary>
 /// <param name="post">a post</param>
 /// <returns>true/false</returns>
 public bool IsExist(TravelPost post)
 {
     return(_postCollection.Contains(post));
 }
Esempio n. 12
0
 /// <summary>
 /// Adds travel post to internal collection
 /// </summary>
 /// <param name="post">a post</param>
 public void Add(TravelPost post)
 {
     _postCollection.Add(post);
 }
Esempio n. 13
0
 /// <summary>
 /// Removes a post from internal collection
 /// </summary>
 /// <param name="post">a post</param>
 /// <returns>true/false value</returns>
 public bool Remove(TravelPost post)
 {
     return(_postCollection.Remove(post));
 }