Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 40
  1. #11
    Join Date
    Feb 2014
    Posts
    277
    Just Google it as quoted: "pluralsight Self Signed Certificate".
    It's a simple gui utility that creates the certificate.
    There may be others or better utilities - it was just one that worked for me.

  2. #12
    Join Date
    Feb 2014
    Posts
    277
    A fun side-track into a parallel universe......

    At this stage I decided to stop the BuzzMMO project just before it heads off into MSBuild-land and go ahead and do Nelson's excellent Comprehensive ASP.NET MVC series where he writes a blogging website. In my opinion, it's the best series he made for 3dBuzz. Whereas the BuzzMMO project goes ahead and writes code, the ASP.NET course takes its time and explains the code in exquisite detail. His sidekick Steve adds smile-worthy humour to the sessions.

    My aim in this is to have a dual understanding of NHibernate and Entity Framework so I can migrate SimpleBlog into BuzzMMO giving the BuzzMMO home page a nice blog system rather than just a way to download the launcher. Since the database tables are completely compatible, mastering the different ORMs should help me merge the two at least at the models and controllers level. No need to mess with the routes at all. One can only hope.

  3. #13
    Join Date
    Nov 2006
    Location
    Vancouver, WA
    Posts
    236
    I will keep checking in to see how this is working out, I am interested in also doing that as well.
    But still finishing up the mmo project videos.
    The only way to fail is to give up or die...

  4. #14
    Join Date
    Feb 2014
    Posts
    277
    I am doing the Comprehensive ASP.NET MVC videos and will add things that look useful into the MMO project. Why not??

    First thing I came across is the red Validation Summary error messages at the end of the video "Working with Data - Creating our User Admin". All it does is make any fields that require input to go red if you don't type in anything. Hey, it looks cool.

    To put that into the BuzzMMO.Web project:
    Find BuzzMMO.Web/Content/Styles/Application.less

    Append to the end of the file:
    Code:
    .field-validation-error {
    	color: red;
    }
    
    .field-validation-valid {
    	display: none;
    }
    
    .input-validation-error {
    	border: 1px solid red;
    	background-color: #ffeeee;
    }
    
    .validation-summary-errors {
    	font-weight: bold;
    	color: red;
    }
    This also works in the Registration form.

    ------------------------------------------------------------------------

    The second thing is the timing attack fix in the video: "Working with Data - Database Driven Auth in ASP.net."
    At the 28'00 mark there is the concept of a fake hash. Basically it tries to take the same amount of time to see if a fake user can login as a real user.
    Only 2 files are altered:

    File #1
    In BuzzMMO.Data/Entities/User.cs find the following lines;

    Code:
    public void SetPassword(string password)
            {
                Password = BCrypt.Net.BCrypt.HashPassword(password, 13);
            }
    replace those lines with:

    Code:
           private const int WorkFactor = 13;
    
           public void SetPassword(string password)
            {
                Password = BCrypt.Net.BCrypt.HashPassword(password, WorkFactor);
            }
    
            public static void FakeHash()
            {
                BCrypt.Net.BCrypt.HashPassword("", WorkFactor);
            }
    You can move the const line to the top of the file if you prefer constants to be at the beginning of a class.

    File #2
    Secondly edit the BuzzMMO.Web/Controllers/AuthController.cs file to add 2 lines.
    Look for these lines:
    Code:
                   var user = database.Users.SingleOrDefault(t => t.Username == form.Username);
                    if (user == null || !user.CheckPassword(form.Password))
                    {
                        ModelState.AddModelError("Password", "Username or Password is incorrect");
                        return View(form);
                    }
    Just after the "var user =" line (about line 23) insert some lines, so that it looks like this:

    Code:
                    var user = database.Users.SingleOrDefault(t => t.Username == form.Username);
    
                    if (user == null)
                        Data.Entities.User.FakeHash();
    
                    if (user == null || !user.CheckPassword(form.Password))
                    {
                        ModelState.AddModelError("Password", "Username or Password is incorrect");
                        return View(form);
                    }

    You can also include those 2 lines in BuzzMMO.Web/Controllers/Api.V1/AuthenticationController.cs in both methods:
    Add them just after the line
    Code:
                var user = _database.Users.SingleOrDefault(f => f.Username == request.Username);
    so that that it looks like:
    Code:
           var user = _database.Users.SingleOrDefault(t => t.Username == request.Username);
           if (user == null)
               Data.Entities.User.FakeHash();
    Last edited by oldngrey; 03-12-2017 at 08:21 PM.

  5. #15
    Join Date
    Feb 2014
    Posts
    277
    The 3rd thing I wanted to add from the SimpleBlog project was the Cross Site Forgery Attacks.
    See the chapter : "Working with Data - Preventing CSRF (Cross Site Forgery Attacks)".

    This isn't as scary as the code quotes below might imply.
    Every Admin HttpPost call is protected by a simple attribute added to the controller and a line added to the top of the views.
    We make a slight change to the _Layout.cshtml file to include the token on the page.
    That would be the end of it if it wasn't for all the "delete" methods which don't have Views. Instead they are sent to the Forms.js file to process. We make some changes to that file so that the token is returned to the delete method.
    It's not hard stuff. It just looks bad because we have to edit most of the files in the admin area.


    The first thing to do was to edit all 4 controllers in the BuzzMMO.Web/Areas/Admin/Controllers folder.
    In each file, find all the methods beginning with [HttpPost] and change it from:

    Code:
            [HttpPost]
    to:
    Code:
            [HttpPost, ValidateAntiForgeryToken]

    Now create a scripts folder BuzzMMO.Web/Areas/Admin/scripts
    and create a file in there called Forms.js
    Edit the file to be:
    Code:
    $(document).ready(function () {
        $("a[data-post]").click(function (e) {
            e.preventDefault();
    
            var $this = $(this);
            var message = $this.data("post");
    
            if (message && !confirm(message))
                return;
    
            var antiForgeryToken = $("#anti-forgery-form input");
            var antiForgeryInput = $("<input type='hidden'>").attr("name", antiForgeryToken.attr("name")).val(antiForgeryToken.val());
    
            $("<form>")
    			.attr("method", "post")
    			.attr("action", $this.attr("href"))
                .append(antiForgeryInput)
    			.appendTo(document.body)
    			.submit();
        });
    
    });
    Since we now have a Forms.js in the frontend as well as the backend now, we should edit
    BuzzMMO.Web/App_Start/BundleConfig.cs and edit the definition for backendScripts to point to the new Forms.js under areas/admin:

    Code:
               var backendScripts = new ScriptBundle("~/js/backend");
                backendScripts.Include("~/scripts/jquery-3.1.1.js", "~/areas/admin/scripts/forms.js");
                backendScripts.Transforms.Add(new JsMinify());
                bundles.Add(backendScripts);
    Now we need to edit the Views cshtml files:

    1. BuzzMMO.Web/Areas/Admin/Views/Shared/_Layout.cshtml
    I will show the last 11 lines. The 3 lines in bold are the additions:

    Code:
           <div class="container">
                @RenderBody()
            </div>
    
            @Scripts.Render("~/js/backend")
    
            <form class="hidden" id="anti-forgery-form">
                @Html.AntiForgeryToken()
            </form>
        </body>
    </html>
    2. BuzzMMO.Web/Areas/Admin/Views/DeployTokens/Create.cshtml
    One line added near the top shown in bold:

    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.DeployTokensCreate
    
    <h1>Create Deploy Token</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    3. BuzzMMO.Web/Areas/Admin/Views/DeployTokens/Index.cshtml
    One line change near the bottom shown in bold:
    Code:
                       <div class="btn-group">
                            <a href="@Url.Action("Delete", new {token.Id})" class="btn btn-xs btn-danger post" data-post="Are you sure you want to delete this token?">
                                <i class="glyphicon glyphicon-remove"></i>
                                delete
                            </a>
                        </div>
    4. BuzzMMO.Web/Areas/Admin/Views/Home/Index.cshtml
    One line added near the top shown in bold:
    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.HomeIndex
    
    <h1>Buzz MMO Settings</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    5. BuzzMMO.Web/Areas/Admin/Views/Roles/Create.cshtml
    One line added near the top shown in bold:
    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.RolesCreate
    
    <h1>Create Role</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    6. BuzzMMO.Web/Areas/Admin/Views/Roles/Edit.cshtml
    One line added near the top shown in bold:
    Code:
    @model  BuzzMMO.Web.Areas.Admin.ViewModels.RolesEdit
    
    <h1>Edit Role @Model.Name</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    7. BuzzMMO.Web/Areas/Admin/Views/Roles/Index.cshtml
    One line change near the bottom shown in bold:

    Code:
                               </a>
                                <a href="@Url.Action("Delete", new {role.Id})" class="btn btn-xs btn-danger post" data-post="Are you sure you want to delete @role.Name?">
                                    <i class="glyphicon glyphicon-remove"></i>
                                    delete
                                </a>
    8. BuzzMMO.Web/Areas/Admin/Views/Users/Create.cshtml
    One line added near the top shown in bold:

    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.UsersCreate
    
    <h1>Create User</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    9. BuzzMMO.Web/Areas/Admin/Views/Users/Edit.cshtml
    One line added near the top shown in bold:

    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.UsersEdit
    
    <h1>Edit User @Model.Username</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">
    10. BuzzMMO.Web/Areas/Admin/Views/Users/Index.cshtml
    One line change near the bottom shown in bold:

    Code:
                               <a href="@Url.Action("Delete", new {user.Id})" class="btn btn-xs btn-danger post" data-post="Are you sure you want to delete @user.Username?">
                                    <i class="glyphicon glyphicon-remove"></i>
                                    delete
                                </a>
    11. BuzzMMO.Web/Areas/Admin/Views/Users/ResetPassword.cshtml
    One line added near the top shown in bold:

    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.UsersResetPassword
    
    <h1>Reset @Model.Username's Password</h1>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
    
        <div class="form-group">


    That's it. The website should act like it did before, but now it's more secure.
    If you get an error trying to delete a token, user, etc, shift-F5 to refresh your browser cache.
    Last edited by oldngrey; 02-24-2017 at 04:19 AM.

  6. #16
    Join Date
    Feb 2017
    Location
    Delhi, IN
    Posts
    0
    Thanks for the post

  7. #17
    Join Date
    Feb 2014
    Posts
    277
    I am now adding in the new Tag and Post tables and its pivot table. These are required before we add in the SimpleBlog system.

    I have decided to only post the changes when I am sure they actually work - ie when some blog posts are actually visible and editable.

    Before you do any of these changes - make sure you backup your MySql database. (MySQL Workbench - Server | Data Export
    Last edited by oldngrey; 03-01-2017 at 01:01 AM.

  8. #18
    Join Date
    Feb 2017
    Posts
    0
    Great <b><a href="http://www.lover-beauty.com/" title="lingerie">lingerie</a></b> can seem like an indulgence, but

    for <b><a href="http://www.lover-beauty.com/" title="wholesale lingerie">wholesale lingerie</a></b> supermodel

    Stephanie Seymour perfecting your bedroom look is worth the effort. “Many women make a mistake in thinking that

    these garments should be worn only for a special occasion when in fact every night is a special occasion,” says

    Seymour. “They’re denying themselves the simple luxury of wearing beautiful lingerie to sleep in.” If anyone

    would know, it’s Seymour, whose name has become synonymous with seductive style. During her decades in fashion,

    she’s served as a model for Victoria’s Secret, established herself a modelingfixture, and cultivated a passion

    for all things boudoir. Now she’s got a line of her own. Created in tandem with designer Casey Paul, Raven &

    Sparrow debuts at Barneys New York this week with a collection filled with decadent, vintage-inspired lingerie.

  9. #19
    Join Date
    Feb 2014
    Posts
    277
    Getting posts to work part 1

    This was done to match the video "Working with Data - Pagination for our Posts Admin" from the "Comprehensive ASP.NET MVC" video series.
    This was done immediately after the video: "Configuring IIS and SSL" in the MMO series.
    ------------------------------------------------------------------------------
    1. Create BuzzMMO.Data/Entities/Post.cs

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace BuzzMMO.Data.Entities
    {
        public class Post
        {
            public int Id { get; set; }
    
            [Required]
            public User User { get; set; }
    
            [Required, MaxLength(128)]
            public string Title { get; set; }
    
            [Required, MaxLength(128)]
            public string Slug { get; set; }
    
            public DateTime CreatedAt { get; set; }
    
            public DateTime? UpdatedAt { get; set; }
    
            public DateTime? DeletedAt { get; set; }
    
            [Required]
            public String Content { get; set; }
    
            public virtual ICollection<Tag> Tags { get; set; }
    
    
            public virtual bool IsDeleted => DeletedAt != null;
        }
    }
    ------------------------------------------------------------------------------
    2. Create BuzzMMO.Data/Entities/Tag.cs

    Code:
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    namespace BuzzMMO.Data.Entities
    {
        public class Tag
        {
            public int Id { get; set; }
    
            [Required, MaxLength(128)]
            public string Slug { get; set; }
    
            [Required, MaxLength(128)]
            public string Name { get; set; }
    
            public virtual ICollection<Post> Posts { get; set; }
        }
    }
    ------------------------------------------------------------------------------
    3. Edit BuzzMMO.Data/MMODatabaseContext.cs
    Note: this file changes later in the series

    Code:
    using System.Data.Entity;
    using BuzzMMO.Base;
    using BuzzMMO.Data.Entities;
    
    namespace BuzzMMO.Data
    {
        public class MMODatabaseContext : DbContext
        {
            public DbSet<Role> Roles { get; set; }
            public DbSet<User> Users { get; set; }
            public DbSet<DeployToken> DeployTokens { get; set; }
    
            public DbSet<Upload> Uploads { get; set; }
            public DbSet<Launcher> Launchers { get; set; }
            public DbSet<Client> Clients { get; set; }
    
            public DbSet<MMOSetting> Settings { get; set; }
    
            public DbSet<ClientAuthenticationToken> ClientAuthenticationTokens { get; set; }
    
            public DbSet<Post> Posts { get; set; }
            public DbSet<Tag> Tags { get; set; }
    
            public MMODatabaseContext() : base("MMODatabase")
            {
            }
    
            protected override void OnModelCreating(DbModelBuilder mapping)
            {
                var buildNumberMap = mapping.ComplexType<BuildNumber>();
                buildNumberMap.Property(t => t.Version);
                buildNumberMap.Property(t => t.Timestamp);
    
                mapping.Entity<Upload>()
                    .Map<Client>(t => t.Requires("Type").HasValue((int) UploadType.Client))
                    .Map<Launcher>(t => t.Requires("Type").HasValue((int) UploadType.Launcher));
    
                mapping.Entity<User>()
                    .HasMany(t => t.Roles)
                    .WithMany(t => t.Users)
                    .Map(t => t.ToTable("UserRoles"));
    
            }
        }
    }
    ------------------------------------------------------------------------------
    4. Create BuzzMMO.Web/Infrastructure/PagedData.cs

    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    namespace BuzzMMO.Web.Infrastructure
    {
        public class PagedData<T> : IEnumerable<T>
        {
            private readonly IEnumerable<T> _currentItems;
    
            public int TotalCount { get; private set; }
            public int Page { get; private set; }
            public int PerPage { get; private set; }
            public int TotalPages { get; private set; }
    
            public bool HasNextPage { get; private set; }
            public bool HasPreviousPage { get; private set; }
    
            public int NextPage
            {
                get
                {
                    if (!HasNextPage)
                        throw new InvalidOperationException();
    
                    return Page + 1;
                }
            }
    
            public int PreviousPage
            {
                get
                {
                    if (!HasPreviousPage)
                        throw new InvalidOperationException();
    
                    return Page - 1;
                }
            }
    
            public PagedData(IEnumerable<T> currentItems, int totalCount, int page, int perPage)
            {
                _currentItems = currentItems;
    
                TotalCount = totalCount;
                Page = page;
                PerPage = perPage;
    
                TotalPages = (int)Math.Ceiling((float)TotalCount / PerPage);
                HasNextPage = Page < TotalPages;
                HasPreviousPage = Page > 1;
            }
    
            public IEnumerator<T> GetEnumerator()
            {
                return _currentItems.GetEnumerator();
            }
    
            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
        }
    }
    ------------------------------------------------------------------------------
    5. Create BuzzMMO.Web/Areas/Admin/Controllers/PostsController.cs
    Note: this file will change again later in the series.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Linq;
    using System.Web.Mvc;
    using BuzzMMO.Web.Areas.Admin.ViewModels;
    using BuzzMMO.Web.Infrastructure;
    //using SimpleBlog.Infrastructure.Extensions;
    using BuzzMMO.Data.Entities;
    using BuzzMMO.Data;
    
    namespace BuzzMMO.Web.Areas.Admin.Controllers
    {
        [Authorize(Roles = "admin")]
        //[SelectedTab("posts")]
        public class PostsController : Controller
        {
            private const int PostsPerPage = 5;
    
            private readonly MMODatabaseContext _database = new MMODatabaseContext();
    
            public ActionResult Index(int page = 1)
            {
                var totalPostCount = _database.Posts.ToList().Count;
    
                var baseQuery = _database.Posts.OrderByDescending(f => f.CreatedAt);
    
                var postIds = baseQuery
                    .Skip((page - 1) * PostsPerPage)
                    .Take(PostsPerPage)
                    .Select(p => p.Id)
                    .ToArray();
    
                var currentPostPage = baseQuery
                    .Where(p => postIds.Contains(p.Id))
                    .Include(f => f.Tags)
                    .Include(f => f.User)
                    .ToList();
    
                return View(new PostsIndex
                {
                    Posts = new PagedData<Post>(currentPostPage, totalPostCount, page, PostsPerPage)
                });
            }
        }
    }
    ------------------------------------------------------------------------------
    6. Create BuzzMMO.Web/Areas/Admin/ViewModels/Posts.cs

    Code:
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using BuzzMMO.Web.Infrastructure;
    using BuzzMMO.Data.Entities;
    
    namespace BuzzMMO.Web.Areas.Admin.ViewModels
    {
        public class TagCheckBox
        {
            public int? Id { get; set; }
            public string Name { get; set; }
            public bool IsChecked { get; set; }
        }
    
        public class PostsIndex
        {
            public PagedData<Post> Posts { get; set; }
        }
    
        public class PostsForm
        {
            public bool IsNew { get; set; }
            public int? PostId { get; set; }
    
            [Required, MaxLength(128)]
            public string Title { get; set; }
    
            [Required, MaxLength(128)]
            public string Slug { get; set; }
    
            [Required, DataType(DataType.MultilineText)]
            public string Content { get; set; }
    
            public IList<TagCheckBox> Tags { get; set; }
        }
    }
    ------------------------------------------------------------------------------
    7. Create BuzzMMO.Web/Areas/Admin/View/Posts/Index.cshtml

    Code:
    @model BuzzMMO.Web.Areas.Admin.ViewModels.PostsIndex
    
    <h1>Posts</h1>
    
    <div class="btn-toolbar">
        <div class="btn-group">
            <a href="@Url.Action("new")" class="btn btn-primary btn-sm"><i class="glyphicon glyphicon-plus"></i>Create Post</a>
        </div>
    
        <div class="btn-group pull-right">
            @if (Model.Posts.HasPreviousPage)
            {
                <a href="@Url.Action("Index", new {page = Model.Posts.PreviousPage})" class="btn btn-primary btn-sm">
                    <i class="glyphicon glyphicon-chevron-left"></i>Previous Page
                </a>}
            else
            {
                <a href="#" class="btn btn-default btn-disabled btn-sm">
                    <i class="glyphicon glyphicon-chevron-left"></i>Previous Page
                </a>}
    
            @if (Model.Posts.HasNextPage)
            {
                <a href="@Url.Action("Index", new {page = Model.Posts.NextPage})" class="btn btn-primary btn-sm">
                    Next Page<i class="glyphicon glyphicon-chevron-right"></i>
                </a>}
            else
            {
                <a href="#" class="btn btn-default btn-disabled btn-sm">
                    Next Page<i class="glyphicon glyphicon-chevron-right"></i>
                </a>}
        </div>
    </div>
    
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Title</th>
                <th>Author</th>
                <th>Tags</th>
                <th>Date</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var post in Model.Posts)
            {
                var cls = "";
                if (post.IsDeleted)
                {
                    cls = "danger";
                }
    
                <tr class="@cls">
                    <td>@post.Title</td>
                    <td>@post.User.Username</td>
                    <td>@string.Join(", ", post.Tags.Select(t => t.Name))</td>
                    <td>@post.CreatedAt</td>
                    <td>
                        <a href="@Url.Action("edit", new {post.Id})" class="btn btn-xs btn-primary">
                            <i class="glyphicon glyphicon-edit"></i>edit
                        </a>
    
                        @if (!post.IsDeleted)
                        {
                            <div class="btn-group btn-group-xs">
                                <a href="@Url.Action("trash", new{post.Id})" class="btn btn-danger" data-post="Are you sure you want to trash this post?">
                                    <i class="glyphicon glyphicon-remove"></i>Trash
                                </a>
                                <a href="#" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="@Url.Action("delete", new{post.Id})" data-post="Are you sure you want to delete this post forever?">
                                            <i class="glyphicon glyphicon-remove"></i>delete
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        }
                        else
                        {
                            <a href="@Url.Action("restore", new{post.Id})" class="btn btn-xs btn-success" data-post="">
                                <i class="glyphicon glyphicon-plus-sign"></i>restore
                            </a>
                        }
                    </td>
                </tr>}
        </tbody>
    </table>
    ------------------------------------------------------------------------------
    8. Edit BuzzMMO.Web/Areas/Admin/View/Shared/_Layout.cshtml
    include the link to the Posts page.

    Code:
    @using System.Web.Optimization
    
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
        <head>
            <title>Buzz MMO - Admin</title>
    
            @Styles.Render("~/styles/backend")
        </head>
        <body>
            <div class="navbar navbar-default">
                <div class="container">
                    <ul class="nav navbar-nav">
                        <li>@Html.ActionLink("Settings", "Index", "Home")</li>
                        <li>@Html.ActionLink("Users", "Index", "Users")</li>
                        <li>@Html.ActionLink("Roles", "Index", "Roles")</li>
                        <li>@Html.ActionLink("Deploy Tokens", "Index", "DeployTokens")</li>
                        <li>@Html.ActionLink("Posts", "Index", "Posts")</li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li>@Html.ActionLink("Back to Home", @"Index", "Home", new { area = "" }, new { })</li>
                    </ul>
                </div>
            </div>
    
            <div class="container">
                @RenderBody()
            </div>
    
            @Scripts.Render("~/js/backend")
            
            <form class="hidden" id="anti-forgery-form">
                @Html.AntiForgeryToken()
            </form>
        </body>
    </html>
    ------------------------------------------------------------------------------
    9. Go to the PackageManagerConsole
    - In the PackageManagerConsole, ensure Default project is BuzzMMO.Data
    - in the Solution Explorer, ensure BuzzMMO.Web is the Startup Project

    Create a migration:

    Code:
    add-migration PostAndTag
    Edit the migration file to match if needed:

    Code:
    namespace BuzzMMO.Data.Migrations
    {
        using System;
        using System.Data.Entity.Migrations;
        
        public partial class PostAndTag : DbMigration
        {
            public override void Up()
            {
                CreateTable(
                    "dbo.Posts",
                    c => new
                        {
                            Id = c.Int(nullable: false, identity: true),
                            Title = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                            Slug = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                            CreatedAt = c.DateTime(nullable: false, precision: 0),
                            UpdatedAt = c.DateTime(precision: 0),
                            DeletedAt = c.DateTime(precision: 0),
                            Content = c.String(nullable: false, unicode: false, storeType: "ntext"),
                            User_Id = c.Int(nullable: false),
                        })
                    .PrimaryKey(t => t.Id)
                    .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
                    .Index(t => t.User_Id);
                
                CreateTable(
                    "dbo.Tags",
                    c => new
                        {
                            Id = c.Int(nullable: false, identity: true),
                            Slug = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                            Name = c.String(nullable: false, maxLength: 128, storeType: "nvarchar"),
                        })
                    .PrimaryKey(t => t.Id);
                
                CreateTable(
                    "dbo.TagPosts",
                    c => new
                        {
                            Tag_Id = c.Int(nullable: false),
                            Post_Id = c.Int(nullable: false),
                        })
                    .PrimaryKey(t => new { t.Tag_Id, t.Post_Id })
                    .ForeignKey("dbo.Tags", t => t.Tag_Id, cascadeDelete: true)
                    .ForeignKey("dbo.Posts", t => t.Post_Id, cascadeDelete: true)
                    .Index(t => t.Tag_Id)
                    .Index(t => t.Post_Id);
                
            }
            
            public override void Down()
            {
                DropForeignKey("dbo.Posts", "User_Id", "dbo.Users");
                DropForeignKey("dbo.TagPosts", "Post_Id", "dbo.Posts");
                DropForeignKey("dbo.TagPosts", "Tag_Id", "dbo.Tags");
                DropIndex("dbo.TagPosts", new[] { "Post_Id" });
                DropIndex("dbo.TagPosts", new[] { "Tag_Id" });
                DropIndex("dbo.Posts", new[] { "User_Id" });
                DropTable("dbo.TagPosts");
                DropTable("dbo.Tags");
                DropTable("dbo.Posts");
            }
        }
    }
    ------------------------------------------------------------------------------
    9. In the PackageManagerConsole
    Type
    Code:
    update-database
    Now go into your sql editor (eg MySql Workbench)
    Check that 3 new tables have been added:
    - posts
    - tags
    - tagposts

    Now right click the posts table and select "Select Rows...."
    I am assuming you have a valid user id from the users table of 1

    Now add in some posts manually. We are only following along with the way Nelson did it.

    Code:
    Id            Title         Slug          CreatedAt                         UpdatedAt     Deleted At     Content              User_Id     
                   post 1      post_1       2017-01-01 00:00:00                                                blegh                 1               
                   post 2      post_2       2017-01-02 00:00:00                                                blegh                 1
    I added in 20 rows to test the pagination.
    Hit the apply button to populate the table.

    ------------------------------------------------------------------------------
    10. Go to the website and go to the Admin panel and click on the new link called Posts
    You should see the posts you added into the database manually. That's all it does...
    Don't click on the edit, delete or new buttons because that's part of the next video.

    Editing is a simple change, but creating is more complicated. This might take some time. This is one area where NHibernate might be more flexible than Entity Framework.
    Last edited by oldngrey; 03-13-2017 at 12:56 AM.

  10. #20
    Join Date
    Nov 2016
    Posts
    1
    Dòng thành ph?m thi?t b? v? sinh Viglacera là dòng công trình ???c phát hành trong n??c vì v?y khi ???c là ??i lý ?y quy?n và là nhà phân ph?i tác ph?m Viglacera , nên khi nh?p hàng giá bao gi? c?ng ???c nhi?u ?u ?ãi nh?t , giá t?t nh?t và tác ph?m ch?t l??ng t?t nh?t.
    Các thành qu? nh?p kh?u t? n??c ngoài v?. ta xin ?oan v?i các chúng ta là giá thành r? nh?t toàn qu?c , do v?i kinh nghi?m và m?i quan h? c?a chúng ta ?ã thành l?p trong h?n tám n?m kinh doanh trong l?nh v?c này . H?i Linh Group ?ã có nh?ng công trình b?o ??m nh?t v? giá thành c?ng nh? ch?t l??ng s?n ph?m .
    Sau h?n tám n?m kinh nghi?m, b?n ?ã t?o ???c th??ng hi?u v?ng ch?c và uy tín v?i các d?ch v? ?i kèm h?n h?n m?t s? hãng khác .
    thi?t b? v? sinh Viglacera ?ã ngày m?t hình thành nhi?u trên th? tr??ng, ???c ng??i dùng tin s? d?ng . . ?ó c?ng là ni?m vinh h?nh cho tôi . , t?i v?i H?i Linh Group khi b?n ch?n mua ch?n b? s?n ph?m nh?: B?n c?u Viglacera , ch?u r?a Viglacera , sen t?m Viglacera s? ???c gi?m giá t? 10 - 30 % .

    1. c? ch? b?o hành dài h?n

    hình th?c b?o hành uy tín và ch?t l??ng ?úng v?i quy ??nh b?o hành c?a công trình b?i hãng niêm y?t.


    2. c? ch? chú tâm và ?áp ?ng khách hàng.
    ??ng c?p , thái ?? ph?c v? c?a nhân viên thân th??ng và chuyên nghi?p, ???c hu?n luy?n bài b?n d?ng , có hi?u bi?t v? công trình ??a ra nh?ng b?n v?n phù h?p nh?t v?i các yêu c?u , ?i?u ki?n c?a khách hàng t?o c?m giác d? ch?u cho khách hàng.

    Hãy t?i v?i showroom Viglacera H?i Linh t?i 275 Khu?t Duy Ti?n ?? hoàn thi?n không gian phòng t?m gia ?ình mình v?i ki?n thi?t ki?n trúc hi?n ??i và sang tr?ng.

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •