示例#1
0
        public ViewResult Details(int id)
        {
            Employee model = _employeerepositry.GetEmployee(id);

            ViewBag.PageTitle = "Details Page";

            return(View(model));
        }
示例#2
0
        public ViewResult Details(int?id)
        //* part 41 - add name parameter public string ViewResult(int? id, string name)
        {
            //* part 41 - model binding maps the incoming http requset (form data, route data, query string data) by name (id and name)
            //* https://localhost:44341/home/Details/2?name=yaron -> "/Details/2" the "id" is part of route date
            //* and "name" "?name=yaron" is part of query string parameter (https://localhost:44341/home is form values)
            //return "id = " + id.Value.ToString() + " name = " + name;
            //* The controller create homeDetailsViewModel object from ViewModels/HomeDetailsViewModel.cs and pass data to Views/Home/Details.cshtml
            //*** with ViewModel we check error on compilation and has insitilaise after @model. in Details.cshtml

            //* Request matched multiple actions resulting in ambiguity -> due to 2 Error.cshtml it failed

            //throw new Exception("Error in Details view " + System.Diagnostics.Process.GetCurrentProcess().ProcessName); //* Pert 60 step 1 - to test global exception - check Development and Production -> next in Startup.cs

            logger.LogTrace("Trace log");
            logger.LogDebug("Debug log");
            logger.LogInformation("Information log");
            logger.LogWarning("Warnnig log");
            logger.LogError("Error log");
            logger.LogCritical("Critical log");


            //* Part 57 - step 1 - Handling 404 not found
            Employee employee = _employeeRepositry.GetEmployee(id.Value);

            if (employee == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", id.Value));
            }

            HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel()
            {
                // Employee = _employeeRepositry.GetEmployee(1),
                Employee  = employee,
                PageTitle = "Employee Details"
            };

            return(View(homeDetailsViewModel));
        }