Online Restaurant Website Part 9 Upload Documents

    Online Restaurant Website Part 9 Upload Documents

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 implement how to upload documents? in asp.net mvc form online restaurant for more details click here: watch video

In this video we are going to add some code to dashboard action to add employee experience and education details with document scan copy and also add some code to dashboard view to get education and experience detail from login employee, once user provide these details correctly after submit perform dashboard action to add provide details to database. for more detail watch video and fallow below step's.. 

 > Add Some Code to Dashboard Action : 

 if (!string.IsNullOrEmpty(dashboardMV.ProfileMV.EducationLevel))
            {
                userdetail.EducationLevel = dashboardMV.ProfileMV.EducationLevel;
                Db.Entry(userdetail).State = System.Data.Entity.EntityState.Modified;
                Db.SaveChanges();
            }
            if (!string.IsNullOrEmpty(dashboardMV.ProfileMV.ExperenceLevel))
            {
                userdetail.ExperenceLevel = dashboardMV.ProfileMV.ExperenceLevel;
                Db.Entry(userdetail).State = System.Data.Entity.EntityState.Modified;
                Db.SaveChanges();
            }

            if (dashboardMV.ProfileMV.EducationLastDegreePhoto != null)
            {
                var folder = "~/Content/OtherFiles";
                var photoname = string.Format("Education_{0}.jpg", userid);
                var response = HelperClass.FileUpload.UploadPhoto(dashboardMV.ProfileMV.EducationLastDegreePhoto, folder, photoname);
                if (response)
                {
                    var photo = string.Format("{0}/{1}", folder, photoname);
                    if (userdetail == null)
                    {
                        userdetail = new UserDetailTable();
                        userdetail.UserDetailID = userid;
                        userdetail.UserID = userid;
                        userdetail.CreatedBy_UserID = userid;
                        userdetail.UserDetailProvideDate = DateTime.Now;
                        userdetail.EducationLastDegreePhotoPath = photo;
                        Db.UserDetailTables.Add(userdetail);
                        Db.SaveChanges();
                    }
                    else
                    {
                        userdetail.EducationLastDegreePhotoPath = photo;
                        userdetail.UserDetailProvideDate = DateTime.Now;
                        Db.Entry(userdetail).State = System.Data.Entity.EntityState.Modified;
                        Db.SaveChanges();
                    }
                }
            }

            if (dashboardMV.ProfileMV.ExperenceLastPhoto != null)
            {
                var folder = "~/Content/OtherFiles";
                var photoname = string.Format("Experience_{0}.jpg", userid);
                var response = HelperClass.FileUpload.UploadPhoto(dashboardMV.ProfileMV.ExperenceLastPhoto, folder, photoname);
                if (response)
                {
                    var photo = string.Format("{0}/{1}", folder, photoname);
                    if (userdetail == null)
                    {
                        userdetail = new UserDetailTable();
                        userdetail.UserDetailID = userid;
                        userdetail.UserID = userid;
                        userdetail.CreatedBy_UserID = userid;
                        userdetail.UserDetailProvideDate = DateTime.Now;
                        userdetail.ExperenceLastPhoto = photo;
                        Db.UserDetailTables.Add(userdetail);
                        Db.SaveChanges();
                    }
                    else
                    {
                        userdetail.ExperenceLastPhoto = photo;
                        userdetail.UserDetailProvideDate = DateTime.Now;
                        Db.Entry(userdetail).State = System.Data.Entity.EntityState.Modified;
                        Db.SaveChanges();
                    }
                }
            }



So now right click on Content folder and create "OtherFiles" folder to save uploaded documents

 

 > Add Some Code to Dashboard View : 

                                        @if (Model.ProfileMV.UserTypeID != 4)
                                        {
                                            <div class="user-change-password mt-4">
                                                <h5>Education + Experence</h5>
                                                <div class="change-password-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.EducationLevel, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Education Level" } })
                                                                @Html.ValidationMessageFor(model => model.ProfileMV.EducationLevel, "", new { @class = "text-danger" })
                                                                <span class="btn btn-default btn-file">
                                                                    @Html.TextBoxFor(model => model.ProfileMV.EducationLastDegreePhoto, new { @class = "upload-pic form-control-file", @type = "file" })
                                                                </span>
                                                            </div>
                                                            <div class="form-group col-md-6">
                                                                @if (string.IsNullOrEmpty(Model.ProfileMV.EducationLastDegreePhotoPath))
                                                                {
                                                                    <label class="text-danger">Upload Last Degree</label>
                                                                }
                                                                else
                                                                {
                                                                    <a href="@Url.Content(Model.ProfileMV.EducationLastDegreePhotoPath)">
                                                                        <img src="@Url.Content(Model.ProfileMV.EducationLastDegreePhotoPath)" style="width:100px;height:150px;max-width: 100%; height: auto;">
                                                                    </a>
                                                                }
                                                            </div>
                                                        </div>

                                                        <div class="form-row">
                                                            <div class="form-group col-md-6">
                                                                @Html.EditorFor(model => model.ProfileMV.ExperenceLevel, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Last Experience Field" } })
                                                                @Html.ValidationMessageFor(model => model.ProfileMV.ExperenceLevel, "", new { @class = "text-danger" })
                                                                <span class="btn btn-default btn-file">
                                                                    @Html.TextBoxFor(model => model.ProfileMV.ExperenceLastPhoto, new { @class = "upload-pic form-control-file", @type = "file" })
                                                                </span>
                                                            </div>
                                                            <div class="form-group col-md-6">
                                                                @if (string.IsNullOrEmpty(Model.ProfileMV.ExperenceLastPhotoPath))
                                                                {
                                                                    <label class="text-danger">Upload Last Experience</label>
                                                                }
                                                                else
                                                                {
                                                                    <a href="@Url.Content(Model.ProfileMV.ExperenceLastPhotoPath)">
                                                                        <img src="@Url.Content(Model.ProfileMV.ExperenceLastPhotoPath)" style="width:100px;height:150px;max-width: 100%; height: auto;">
                                                                    </a>
                                                                }
                                                            </div>
                                                        </div>

                                                        <div class="form-group mb-0 pt-4 text-center">
                                                            <button class="btn btn-theme btn-md" type="submit">Submit</button>
                                                        </div>
                                                    }
                                                </div>
                                            </div>
                                        }