Online Restaurant Website Part 8 User Setting

   Online Restaurant Website Part 8 User Setting

Hi, Dear's here we learn how to implement Restaurant Website in Visual Studio using C# ASP.NET MVC. Ilyasoft software company provide full project step by step training on our YouTube Channel ilyasoft software company so now subscribe, share and like for more project base tutorials



In this video we are going to User setting in asp.net mvc form online restaurant for more details click here: watch video

First we are going to set layout and then user dashboard

 > User_ProfileMV Code : 

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Web;

namespace PizzaRestaurantDrink.Models
{
    public class User_ProfileMV
    {
        public int UserID { get; set; }
        public string UserType { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string FullName { get; set; }
        public string ContactNo { get; set; }
        public string GenderTitle { get; set; }
        public string EmailAddress { get; set; }
        public System.DateTime RegisterationDate { get; set; }
        [DataType(DataType.MultilineText)]
        public string FullAddress { get; set; }
        public string UserStatus { get; set; }
        public int UserStatusID { get; set; }
        public Nullable<System.DateTime> UserStatusChangeDate { get; set; }
        public System.DateTime UserDetailProvideDate { get; set; }
        public string PhotoPath { get; set; }
        public string CNIC { get; set; }
        public string EducationLevel { get; set; }
        public string ExperenceLevel { get; set; }
        public string EducationLastDegreePhotoPath { get; set; }
        public string ExperenceLastPhotoPath { get; set; }

        [NotMapped]
        [Display(Name = "Profile Photo")]
        public HttpPostedFileBase UserPhoto { get; set; }
        [NotMapped]
        [Display(Name = "Education Last Degree Scan Photo")]
        public HttpPostedFileBase EducationLastDegreePhoto { get; set; }
        [NotMapped]
        [Display(Name = "Last Experience Scan Photo")]
        public HttpPostedFileBase ExperenceLastPhoto { get; set; }

    }
}

Next we add Folder for Helper Code or Optimized Code.
So Now Right click on PizzaRestaurantDrink and create folder (Name : HelperClass)

Next we add class to upload file | photo
So now right click on HelperClass folder and create "FileUpload" class and then add below code.

> FileUpload Code : 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace PizzaRestaurantDrink.HelperClass
{
    public class FileUpload
    {
        public static bool UploadPhoto(HttpPostedFileBase file, string folder, string name)
        {
            if (file == null || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(folder))
            {
                return false;
            }
            try
            {
                string path = string.Empty;
                if (file != null)
                {
                    path = Path.Combine(HttpContext.Current.Server.MapPath(folder), name);
                    file.SaveAs(path);
                    using (MemoryStream ms = new MemoryStream())
                    {
                        file.InputStream.CopyTo(ms);
                        byte[] array = ms.GetBuffer();
                    }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

Once the above step is done then right click on content folder and add "ProfilePhoto" folder inside in Content Folder.

Next fallow the below step.

 > DashboardMV Code : 

using DBLayer;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace PizzaRestaurantDrink.Models
{
    public class DashboardMV
    {
        PizzaRestaurentandDrinksDbEntities db = new PizzaRestaurentandDrinksDbEntities();
        public DashboardMV()
        {
            ProfileMV = new User_ProfileMV();
        }
        public DashboardMV(int? id)
        {
            ProfileMV = new User_ProfileMV();
            var user = db.UserTables.Find(id);
            ProfileMV.UserID = user.UserID;
            ProfileMV.UserType = user.UserTypeTable.UserType;
            ProfileMV.UserName = user.UserName;
            ProfileMV.Password = user.Password;
            ProfileMV.FirstName = user.FirstName;
            ProfileMV.LastName = user.LastName;
            ProfileMV.FullName = string.Format("{0} {1}", user.FirstName, user.LastName);
            ProfileMV.ContactNo = user.ContactNo;
            ProfileMV.GenderTitle = user.GenderTable.GenderTitle;
            ProfileMV.EmailAddress = user.EmailAddress;
            ProfileMV.RegisterationDate = user.RegisterationDate;
            var userpersonaladdress = db.UserAddressTables.Where(u => u.UserID == user.UserID).FirstOrDefault();

            ProfileMV.FullAddress = userpersonaladdress != null ? userpersonaladdress.FullAddress : string.Empty;
            ProfileMV.UserStatus = user.UserStatusTable.UserStatus;
            ProfileMV.UserStatusID = user.UserStatusID;
            ProfileMV.UserStatusChangeDate = user.UserStatusChangeDate;
            if (user.UserDetailTable != null)
            {
                ProfileMV.UserDetailProvideDate = user.UserDetailTable.UserDetailProvideDate;
                ProfileMV.PhotoPath = user.UserDetailTable.PhotoPath;
                ProfileMV.CNIC = user.UserDetailTable.CNIC;
                ProfileMV.EducationLevel = user.UserDetailTable.EducationLevel;
                ProfileMV.ExperenceLevel = user.UserDetailTable.ExperenceLevel;
                ProfileMV.EducationLastDegreePhotoPath = user.UserDetailTable.EducationLastDegreePhotoPath;
                ProfileMV.ExperenceLastPhotoPath = user.UserDetailTable.ExperenceLastPhoto;
            }
        }
        public virtual User_ProfileMV ProfileMV { get; set; }

        [DataType(DataType.Password)]
        public string OldPassword { get; set; }

        [DataType(DataType.Password)]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        public string ConfirmPassword { get; set; }

    }
}

So Now Add Dashboard code to User Controller.

> Dashboard Action Code :  
   add below code. 

public ActionResult Dashboard()
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["UserTypeID"])))
            {
                return RedirectToAction("Index","Home");
            }

            int userid = 0;
            if (!string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
            {
                int.TryParse(Convert.ToString(Session["UserID"]), out userid);
            }

            var dashboard = new DashboardMV(userid);
            return View(dashboard);
        }

        [HttpPost]
        public ActionResult Dashboard(DashboardMV dashboardMV)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["UserTypeID"])))
            {
                return RedirectToAction("Login", "User");
            }
            int userid = 0;
            if (!string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
            {
                int.TryParse(Convert.ToString(Session["UserID"]), out userid);
            }
            var dasboard = new DashboardMV(userid);
            if (!string.IsNullOrEmpty(dashboardMV.OldPassword))
            {

                if (dasboard.ProfileMV.Password == dashboardMV.OldPassword)
                {
                    if (dashboardMV.NewPassword.Trim() == dashboardMV.ConfirmPassword.Trim())
                    {
                        var user = Db.UserTables.Find(userid);
                        user.Password = dashboardMV.NewPassword;
                        Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                        Db.SaveChanges();
                        ModelState.AddModelError("OldPassword", "Password Changed");
                    }
                }
                else
                {
                    ModelState.AddModelError("OldPassword", "Old Password is Incorrect!");
                }
            }
            if (!string.IsNullOrEmpty(dashboardMV.ProfileMV.FirstName) &&
               !string.IsNullOrEmpty(dashboardMV.ProfileMV.LastName) &&
               !string.IsNullOrEmpty(dashboardMV.ProfileMV.EmailAddress) &&
               !string.IsNullOrEmpty(dashboardMV.ProfileMV.ContactNo))
            {
                var user = Db.UserTables.Find(userid);
                user.FirstName = dashboardMV.ProfileMV.FirstName;
                user.LastName = dashboardMV.ProfileMV.LastName;
                user.EmailAddress = dashboardMV.ProfileMV.EmailAddress;
                user.ContactNo = dashboardMV.ProfileMV.ContactNo;
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                Db.SaveChanges();
                if (dashboardMV.ProfileMV.UserPhoto != null)
                {
                    var folder = "~/Content/ProfilePhoto";
                    var photoname = string.Format("{0}.jpg", user.UserID);
                    var response = HelperClass.FileUpload.UploadPhoto(dashboardMV.ProfileMV.UserPhoto, folder, photoname);
                    if (response)
                    {
                       var photo = string.Format("{0}/{1}", folder, photoname);
                       var userdetail = Db.UserDetailTables.Find(userid);
                        if (userdetail == null)
                        {
                            userdetail = new UserDetailTable();
                            userdetail.UserDetailID = userid;
                            userdetail.UserID = userid;
                            userdetail.CreatedBy_UserID = userid;
                            userdetail.UserDetailProvideDate = DateTime.Now;
                            userdetail.PhotoPath = photo;
                            Db.UserDetailTables.Add(userdetail);
                            Db.SaveChanges();
                        }
                        userdetail.PhotoPath = photo;
                        userdetail.UserDetailProvideDate = DateTime.Now;
                        Db.Entry(userdetail).State = System.Data.Entity.EntityState.Modified;
                        Db.SaveChanges();
                    }
                }
                ModelState.AddModelError(string.Empty, "Updated");
            }
            return View(dasboard);
        }

 > Dashboard View Code : 

@model PizzaRestaurantDrink.Models.DashboardMV
@{
    ViewBag.Title = "Dashboard";
}

<!-- Breadcrumb Start -->
<div class="bread-crumb">
    <div class="container">
        <div class="matter">
            <h2>Dashboard</h2>
            <ul class="list-inline">
                <li class="list-inline-item"><a href="@Url.Content("~/Home/Index")">HOME</a></li>
                <li class="list-inline-item"><a href="#">Dashboard</a></li>
            </ul>
        </div>
    </div>
</div>
<!-- Breadcrumb End -->
<!-- Deshboard Start -->
<div class="dashboard">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-sm-12 commontop text-center">
                <h4>User Dashboard</h4>
                <div class="divider style-1 center">
                    <span class="hr-simple left"></span>
                    <i class="icofont icofont-ui-press hr-icon"></i>
                    <span class="hr-simple right"></span>
                </div>
            </div>
            <div class="col-lg-12 col-md-12 user-profile">
                <div class="row">
                    <div class="col-md-3 col-lg-2">
                        <div class="user-profile-tabs">
                            <!--  Menu Tabs Start  -->
                            <ul class="nav nav-tabs flex-column">
                                <li class="nav-item">
                                    <a class="nav-link active" data-toggle="tab" href="#overview" aria-expanded="true">
                                        <i class="icofont icofont-dashboard-web"></i>
                                        <span>Overview</span>
                                    </a>
                                </li>
                                <li id="navprofile" class="nav-item">
                                    <a class="nav-link" data-toggle="tab" href="#profile" aria-expanded="true">
                                        <i class="icofont icofont-ui-user"></i>
                                        <span>Profile</span>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" data-toggle="tab" href="#history" aria-expanded="true">
                                        <i class="icofont icofont-history"></i>
                                        <span>History</span>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" data-toggle="tab" href="#cards" aria-expanded="true">
                                        <i class="icofont icofont-credit-card"></i>
                                        <span>My Card</span>
                                    </a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" data-toggle="tab" href="#complaint" aria-expanded="true">
                                        <i class="icofont icofont-support-faq"></i>
                                        <span>Complaint</span>
                                    </a>
                                </li>

                            </ul>
                            <!--  Menu Tabs Start  -->
                        </div>
                    </div>
                    <div class="col-md-9 col-lg-10">
                        <div class="tab-content">
                            <div id="overview" class="tab-pane fade active show">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="brief-info">
                                            <div class="media">
                                                <img class="mr-3" src="@Url.Content(Model.ProfileMV.PhotoPath)" style="width:100px;height:150px;max-width: 100%; height: auto;" alt="User">
                                                <div class="media-body">
                                                    <h4>@Model.ProfileMV.FullName</h4>
                                                    <p><i class="icofont icofont-envelope"></i> @Model.ProfileMV.EmailAddress</p>
                                                    <p><i class="icofont icofont-phone"></i> @Model.ProfileMV.ContactNo</p>
                                                    @if (Model.ProfileMV.UserStatusID == 1 || Model.ProfileMV.UserStatusID == 6)
                                                    {
                                                        <p class="confirmed"><i class="icofont icofont-check"></i>@Model.ProfileMV.UserStatus</p>
                                                    }
                                                    else
                                                    {
                                                        <p class="failed"><i class="icofont icofont-close"></i>@Model.ProfileMV.UserStatus</p>
                                                    }
                                                </div>
                                            </div>
                                            <div class="brief-info-footer" style="background-color: #e54c2a">
                                                <p style="font-size:medium; text-align:center;">  <i class="icofont icofont-ui-user"></i>@Model.ProfileMV.UserType </p>
                                            </div>
                                        </div>
                                    </div>


                                </div>
                            </div>

                            <div id="profile" class="tab-pane fade">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="user-personal-info">
                                            <h5>Personal Information</h5>
                                            <div class="user-info-body">
                                                @using (Html.BeginForm("Dashboard", "User", FormMethod.Post, new { @enctype = "multipart/form-data" }))
                                                {
                                                    @Html.AntiForgeryToken()
                                                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                                                    <div class="form-row">
                                                        <div class="form-group col-md-6">
                                                            @Html.EditorFor(model => model.ProfileMV.FirstName, new { htmlAttributes = new { @class = "form-control", @type = "text", @placeholder = "Enter First Name" } })
                                                            @Html.ValidationMessageFor(model => model.ProfileMV.FirstName, "", new { @class = "text-danger" })
                                                        </div>
                                                        <div class="form-group col-md-6">
                                                            @Html.EditorFor(model => model.ProfileMV.LastName, new { htmlAttributes = new { @class = "form-control", @type = "text", @placeholder = "Enter Last Name" } })
                                                            @Html.ValidationMessageFor(model => model.ProfileMV.LastName, "", new { @class = "text-danger" })
                                                        </div>
                                                    </div>
                                                    <div class="form-row">
                                                        <div class="form-group col-12">
                                                            @Html.EditorFor(model => model.ProfileMV.EmailAddress, new { htmlAttributes = new { @class = "form-control", @type = "email", @placeholder = "Enter Email Address" } })
                                                            @Html.ValidationMessageFor(model => model.ProfileMV.EmailAddress, "", new { @class = "text-danger" })
                                                        </div>
                                                    </div>
                                                    <div class="form-row">
                                                        <div class="form-group col-12">
                                                            @Html.EditorFor(model => model.ProfileMV.ContactNo, new { htmlAttributes = new { @class = "form-control", @type = "tel", @placeholder = "Enter Contact Number" } })
                                                            @Html.ValidationMessageFor(model => model.ProfileMV.ContactNo, "", new { @class = "text-danger" })
                                                        </div>
                                                    </div>
                                                    <div class="form-row">
                                                        <div class="form-group col-12">
                                                            @Html.EditorFor(model => model.ProfileMV.FullAddress, new { htmlAttributes = new { @class = "form-control", @placeholder = "Your Current Address" } })
                                                            @Html.ValidationMessageFor(model => model.ProfileMV.FullAddress, "", new { @class = "text-danger" })
                                                        </div>
                                                    </div>
                                                    <div class="form-row">
                                                        <div class="form-group col-12">
                                                            <label>Upload Photo</label>
                                                            <span class="btn btn-default btn-file">
                                                                @Html.TextBoxFor(model => model.ProfileMV.UserPhoto, new { @class = "upload-pic form-control-file", @type = "file" })
                                                            </span>
                                                        </div>
                                                    </div>
                                                    <div class="form-row">
                                                        <div class="form-group mb-0 pt-4 col-12 text-center">
                                                            <button class="btn btn-theme btn-md" type="submit">SAVE CHANGES</button>
                                                            <a class="btn btn-theme btn-md btn-wide" href="@Url.Content("~/User/Dashboard")">CANCEL</a>
                                                        </div>
                                                    </div>
                                                }
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-lg-6">
                                        <div class="user-change-password">
                                            <h5>Change Password</h5>
                                            <div class="change-password-body">
                                                @using (Html.BeginForm("Dashboard", "User"))
                                                {
                                                    @Html.AntiForgeryToken()
                                                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                                                    <div class="form-group">
                                                        @Html.EditorFor(model => model.OldPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "Old Password" } })
                                                        @Html.ValidationMessageFor(model => model.OldPassword, "", new { @class = "text-danger" })
                                                    </div>
                                                    <div class="form-group">
                                                        @Html.EditorFor(model => model.NewPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "New Password" } })
                                                        @Html.ValidationMessageFor(model => model.NewPassword, "", new { @class = "text-danger" })
                                                    </div>
                                                    <div class="form-group">
                                                        @Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control", @placeholder = "Confirm Password" } })
                                                        @Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
                                                    </div>
                                                    <div class="form-group mb-0 pt-4 text-center">
                                                        <button class="btn btn-theme btn-md" type="submit">CHANGE PASSWORD</button>
                                                    </div>
                                                }
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
  
                        </div>
                    </div>



                </div>
            </div>
        </div>
    </div>
</div>
<!-- Deshboard End -->


Layout Setting

 Register View Code : 

@{
    int userid = 0, usertypeid = 0;
    if (!string.IsNullOrEmpty(Convert.ToString(Session["UserID"])))
    {
        int.TryParse(Convert.ToString(Session["UserID"]), out userid);
    }
    if (!string.IsNullOrEmpty(Convert.ToString(Session["UserTypeID"])))
    {
        int.TryParse(Convert.ToString(Session["UserTypeID"]), out usertypeid);
    }
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="theme-color" content="#e54c2a">
        <!-- Favicon -->
        <link type="image/x-icon" rel="shortcut icon" href="favicon.png" />
        <title>PIZZA - Restaurant and Drinks</title>
        <meta name="description" content="Pizza - Restaurant, food and Drinks,">

        <!-- Bootstrap stylesheet -->
        .....
    </head>
    <body class="">
        <div class="wrapper">
            <!-- Loader Start -->
            <div class="loader">
                ......
            </div>
            <!-- Loader End -->
            <!--  Header Start  -->
            <header>
                <!--Top Header Start -->
                <div class="top">
                    <div class="container">
                        <div class="row">
                            <div class="col-sm-12 col-12">
                                <ul class="list-inline float-left icon">
                                    <li class="list-inline-item"><a href="#"><i class="icofont icofont-phone"></i> Hotline : +92 314 307 6781</a></li>
                                </ul>
                                <!-- Header Social Start -->
                                <ul class="list-inline float-right icon">
                                    <li class="list-inline-item"><a href="shopping-cart.html"><i class="icofont icofont-cart-alt"></i> Cart</a></li>
                                    <li class="list-inline-item dropdown">
                                        <a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="icofont icofont-ui-user"></i> My Account</a>
                                        <ul class="dropdown-menu dropdown-menu-right drophover" aria-labelledby="dropdownMenuLink">
                                            @if (userid <= 0)
                                            {
                                                <li class="dropdown-item"><a href="@Url.Content("~/User/Login")">Login</a></li>
                                                <li class="dropdown-item"><a href="@Url.Content("~/User/Register")">Register</a></li>
                                            }
                                            else
                                            {
                                                <li class="dropdown-item"><a href="@Url.Content("~/User/Dashboard")">Dashboard</a></li>
                                                <li class="dropdown-item"><a href="@Url.Content("~/User/Logout")">Logout</a></li>
                                            }
                                        </ul>
                                    </li>
                                    <li class="list-inline-item">
                                        .....
                                    </li>
                                </ul>
                                <!-- Header Social End -->
                            </div>
                        </div>
                    </div>
                </div>
                <!--Top Header End -->

                <div class="container">
                    <div class="row">
                        <div class="col-md-3 col-sm-6 col-12">
                            <!-- Logo Start  -->
                            <div id="logo">
                                <a href="@Url.Content("~/Home/Index")"><img id="logo_img" class="img-fluid" src="~/Content/Template/assets/images/logo/logo.png" alt="logo" title="logo" /></a>
                            </div>
                            <!-- Logo End  -->
                        </div>

                        <div class="col-md-7 col-sm-6 col-12 paddleft">
                            <!-- Main Menu Start  -->
                            <div id="menu">
                                <nav class="navbar navbar-expand-md">
                                    <div class="navbar-header">
                                        <span class="menutext d-block d-md-none">Menu</span>
                                        <button data-target=".navbar-ex1-collapse" data-toggle="collapse" class="btn btn-navbar navbar-toggler" type="button"><i class="icofont icofont-navigation-menu"></i></button>
                                    </div>
                                    <div class="collapse navbar-collapse navbar-ex1-collapse padd0">
                                        <ul class="nav navbar-nav">
                                            <li class="nav-item"><a href="@Url.Content("~/Home/Index")">HOME</a></li>
                                            <li class="nav-item"><a href="#">about us</a></li>
                                            <li class="nav-item"><a href="#">Our Menu</a></li>
                                            @if (usertypeid == 1 || usertypeid == 3)
                                            {
                                                <li class="nav-item dropdown">
                                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Setting</a>
                                                    <div class="dropdown-menu">
                                                        <div class="dropdown-inner">
                                                            <ul class="list-unstyled">
                                                                <li><a href="@Url.Content("~/Setting/List_UserTypes")">User Types</a></li>
                                                                <li><a href="@Url.Content("~/Setting/List_Genders")">Genders</a></li>
                                                                <li><a href="@Url.Content("~/Setting/List_UserStatus")">Account Status</a></li>
                                                                <li><a href="@Url.Content("~/Setting/List_VisibleStatus")">Record Visible Status</a></li>
                                                            </ul>
                                                        </div>
                                                    </div>
                                                </li>
                                            }
                                            <li class="nav-item"><a href="#">Our Blog</a></li>
                                            <li class="nav-item"><a href="#">contact us</a></li>
                                        </ul>
                                    </div>
                                </nav>
                            </div>
                            <!-- Main Menu End -->
                        </div>
                        <div class="col-md-2 col-sm-12 col-12 button-top paddleft">
                            <a class="btn-primary btn" href="#">Book Your Table</a>
                        </div>
                    </div>
                </div>
            </header>
            <!-- Header End   -->
            @RenderBody()
            <!-- Footer Start -->
            .....

        </div>

        ........
    </body>

</html>
}
<!-- Layout End -->