Giter Site home page Giter Site logo

vidly-mvc-5's People

Contributors

mosh-hamedani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vidly-mvc-5's Issues

The commits don

Am I missing something or is the database excluded when I download the commits? That's very annoying when a lecture builds on a previous exercise and my solution isn't EXACTLY the way it is in yours.

What's the easiest way to rebuild the database based on the migration files? "update-database" isn't working for me.

ModelBinding

hiii Mosh,When i use CustomerFormViewModel in save action the data traveled view to controller but when i use Customer class instead of CustomerFormViewModel my obj receive no data

public ActionResult Savee(Customer customer) in this customer object recieve no data

Cannot Log with Facebook

I had the following error on FB: "Impossible de charger l’URL: Le domaine de cet URL n’est pas compris dans le domaine de l’application. Pour être en mesure de charger cet URL, ajoutez tous les domaines et sous-domaines de votre application dans le champ "App Domaines" dans les paramètres de l’application."
(Impossible to load the URL: the URL domain is not included in the application domain blablabla".

Sounds like FB wants me to add some domain information, which is not in the Mosh's course and what domain ? I'm on my perso machine.

Thanks if someone can help ! :-)

web page interface for Rentals Table

Hello everyone! I've been trying to add a webpage for Rentals table, to see who and what rented. However, I've come across some issues. I would be very glad if you were willing to take a look at it, maybe you could be able to help me, given the fact that you are all familiar with the vidly project.

The table looks like this:
image

This is the Model:

using System;
using System.ComponentModel.DataAnnotations;

namespace Vidly.Models
{
    public class Rental
    {
        public int Id { get; set; }

        [Required]
        public Customer Customer { get; set; }

        [Required]
        public Movie Movie { get; set; }

        public DateTime DateRented { get; set; }
   
        public DateTime? DateReturned { get; set; }
    }
}

I've created an API Controller which looks like this

using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Vidly.Dtos;
using Vidly.Models;
using System.Data.Entity;


namespace Vidly.Controllers.Api
{
    public class RentalsController : ApiController
    {

        private ApplicationDbContext _context;

        public RentalsController()
        {
            _context = new ApplicationDbContext();
        }

        // GET /api/rentals
        public IHttpActionResult GetRentals(string query = null)
        {
            var rentalsQuery = _context.Rentals
                .Include(r => r.Customer)
                .Include(r => r.Movie);

            var rentalDtos = rentalsQuery
                .ToList()
                .Select(Mapper.Map<Rental, RentalDto>);

            return Ok(rentalDtos);
        }

        // GET /api/rentals/1
        public IHttpActionResult GetRental(int id)
        {
            var rental = _context.Rentals.SingleOrDefault(r => r.Id == id);

            if (rental == null)
                return NotFound();

            return Ok(Mapper.Map<Rental, RentalDto>(rental));
        }
    }
}

and another Controller which looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;
using System.Data.Entity;
using Vidly.ViewModels;

namespace Vidly.Controllers
{
    public class RentalsController : Controller
    {
        private ApplicationDbContext _context;

        [Authorize(Roles = RoleName.CanManageMovies)]
        public ViewResult Index()
        {
            if (User.IsInRole(RoleName.CanManageMovies))
                return View("Index");
            else
                return View("Home");
        }
        public ActionResult New()
        {
            return View();
        }

        public ActionResult Details(int id)
        {
            var rental = _context.Rentals.Include(r => r.Movie).Include(r => r.Customer).SingleOrDefault(r => r.Id == id);

            if (rental == null)
                return HttpNotFound();

            return View(rental);
        }

    }
}

Finally, the cshtml file looks something like this:

@model IEnumerable<Vidly.Models.Rental>
@{
    ViewBag.Title = "Rentals";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Rentals</h2>

<table id="rentals" class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>Customer</th>
            <th>Movie</th>
            <th>Date Rented</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>

@section scripts
{
    <script>
        $(document).ready(function () {
            var table = $("#rentals").DataTable({
                ajax: {
                    url: "/api/rentals",
                    dataSrc: ""
                },
                columns: [
                    {
                        data: "customer.name"
                    },
                    {
                        data: "movie.name"
                    },
                    {
                        data: "daterented"
                    }
                ]
            });

        });
    </script>
}

The problem is that whenever I'm trying to access the web page, I'm getting this error message 5 times, for every entry in the table:

DataTables warning: table id=rentals - Requested unknown parameter
'daterented' for row 0, column 2. For more information about this
error, please see http://datatables.net/tn/4

The table looks like this:
image

And the XML file (available when accessing https://localhost:44300/api/rentals) from where the data for the table should be fetched looks like this:
image

I would be very glad if you could help me out with this problem!
Many thanks!

The INSERT statement conflicted with the FOREIGN KEY constraint

I'm trying to add few entries to the customer table (In fact in several tables) and I'm getting this error.

The INSERT statement conflicted with the FOREIGN KEY constraint ...... The conflict occurred in database ..... column 'Id'

I tried to search on Stackoverflow and I'm given a hint that I should populate the foreign key data after updating the parent table data only. I've tried my best, regenerating the tables, deleting data, deleting migrations and several database update attempts.

I even tried to make the whole project from start and stuck at the same place.
Any ideas how to deal with it?

How to clone this to a new computer?

Hey :) How can you just clone this to your computer and then run it? It wont ofc have the database avaialble, but can i just clone the project from here and then run update-database? what are the steps? :D thanks <3

Problems with deploying the DB

I can't seem to include my very first migration in the script. (I can probably do it manually, but I want to learn how to use the tools available.) In package manager, I do the following

update-database -script

and it gives me an empty file and says, "no pending explicit migrations." So I try to explicitly state the first migration in order to get them all, like this:

update-database -script - sourceMigration:MyInitialMigrationName

but then it gives me a script for all the migrations starting with the second one, the one right after the one I named. So I can't seem to include that first migration's SQL on my script. Can someone help?

Returning a movie

Is there anyone who managed to extend this so that you can actually see when the customer has returned a movie?

Final touches issue

I changed the typeahead.css file to include the 3 changes as stated but as I do an Inspect, they still show and use the original values. I shut the PC off and started again, still the same. Why does it not recognize them? For instance, when hovering, the background-color it should be green.
screen shot1
screen shot 2

Null reference error

Hello Mosh,

hope this meets you well, i will love it if you can help with this error trace. deleted the required attribute of Genre and i left the one for GnereId because i had all of them on the required annotation, afterwards i did the EF add migration and update-database. the error i get is this below and when i rerun the app i find it has added to the DB because it will list it out int he movie list .

image

about Migrations

i am getting error while enable migrations no context was found
i dont know where you declare context class
how u got intialmodel class in models folder.can anyone helpme

Add Movie does not set NumberAvailable

NumberAvailable column of movie table is not set anywhere in the code so when a new movie inserted it remains null. Nobody can see the newly added movies, unless he or she manually updates database and set NumberAvailable to a number greater than zero.

By the way, thanks for this wonderful and awesome course and project.

Database issue

On this moment i'm following the course of Mosh working with data in the Vidly project, but i'm trying in the package manager console to update the database. When i type update-database there is no such file comming in my App_Date even with the option to show all the hidden files. Am i doing something wrong or do i need to have a own sql database?

Auto-complete in Rentals-View

Hi, i´ve got a problem with the bloodhound-part, the autocomplete.... It works fine for the customers, but it doesn´t recognize any movie. After feeling "I dont´t know anymore what to do", i´ve copied the code from here to my project but it still doesn´t work. I compared the newRentalDto, the moviesModel, the RentalModel and the New.cshtml but I couldn´t find the error. Anyone else with the same problems or any idea? Thanks a lot and sorry for my improvable english.......

Haeder is not coming in correct format

Hi. After copying and paste lumen bootstrap.cc in content folder, Header is not coming in the correct format.
What are may be a possible mistake I am doing?
image

getting errorwhile add-migration seedUsers

Unable to generate an explicit migration because the following explicit migrations are pending: [201806071448573_InitialModel, 201806071511521_AddIsSubscribedToCustomer, 201806071524212_AddMembershipType, 201806071532498_PopulateMembershipTypes, 201806071616581_applyAnnotationsToCustomerName, 201806071802256_AddNameToMembershipType, 201806071803513_UpdateMembershipTypes, 201806071811417_AddBirthDateToCustomers, 201806071837325_AddPropertiesToMovie, 201806071841532_PopulateGenre, 201806071917517_AddPropertiesToMovie1]. Apply the pending explicit migrations before attempting to generate a new explicit migration.

Googled it and tried fixing but still not working
Pls help...

No solution for Section 2 identified in code?

Hi, do not find this solution directory very useful as a way of checking what I have done for the exercise. There are layers of code from subsequent sections on top of the sol 2 code which I am after. It would perhaps have been more useful to have stand alone solution files rather than the whole complete solution which I do not have time to pick through.

Thanks,

Lesson 10 NewRental API Issue

I keep getting an internal server 500 error when trying to use Postman to post to the new rentals table.
Controllers/Api/NewRentalsController:

using System;
using System.Linq;
using System.Web.Http;
using udemy_Vidly.Dto;
using udemy_Vidly.Models;

namespace udemy_Vidly.Controllers.Api
{
public class NewRentalsController : ApiController
{
private ApplicationDbContext _context;

    public NewRentalsController()
    {
        _context = new ApplicationDbContext();
    }

    public IHttpActionResult GetMovies(NewRentalDto newRental)
    {
        var moviesQuery = _context.Rentals.ToList();

        return Ok(moviesQuery);

    }

    [HttpPost]
    public IHttpActionResult CreateNewRentals(NewRentalDto newRental)
    {
        var customer = _context.Customers.Single(c => c.Id == newRental.CustomerId);

        var movies = _context.Movies.Where(m => newRental.MovieId.Contains(m.Id));

        foreach (var movie in movies)
        {
            if (movie.NumberAvailable == 0)
                return BadRequest("Movie is not available.");

            movie.NumberAvailable--;

            var rental = new Rental
            {
                Customer = customer,
                Movie = movie,
                DateRented = DateTime.Now
            };

            _context.Rentals.Add(rental);
        }

        _context.SaveChanges();

        return Ok(customer);
    }

}

}

Controllers/NewRentalsController:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace udemy_Vidly.Controllers
{
public class NewRentalsController : Controller
{
// GET: Rentals
public ActionResult New()
{
return View();
}
}
}

Dto/NewRentalDto:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace udemy_Vidly.Dto
{
public class NewRentalDto
{
public int CustomerId { get; set; }
public List MovieId { get; set; }
}
}

Models/Rental
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace udemy_Vidly.Models
{
public class Rental
{
public int Id { get; set; }

    [Required]
    public Customer Customer { get; set; }

    [Required]
    public Movie Movie { get; set; }

    public DateTime DateRented { get; set; }

    public DateTime? DateReturned { get; set; }
}

}

Controllers/NewRentalsController

sing System;
using System.Linq;
using System.Web.Http;
using udemy_Vidly.Dto;
using udemy_Vidly.Models;

namespace udemy_Vidly.Controllers.Api
{
public class NewRentalsController : ApiController
{
private ApplicationDbContext _context;

    public NewRentalsController()
    {
        _context = new ApplicationDbContext();
    }


    [HttpPost]
    public IHttpActionResult CreateNewRentals(NewRentalDto newRental)
    {
        var customer = _context.Customers.Single(c => c.Id == newRental.CustomerId);

        var movies = _context.Movies.Where(m => newRental.MovieId.Contains(m.Id));

The debugger shows movies and customer variables here returning null values
foreach (var movie in movies)
{
if (movie.NumberAvailable == 0)
return BadRequest("Movie is not available.");

            movie.NumberAvailable--;

            var rental = new Rental
            {
                Customer = customer,
                Movie = movie,
                DateRented = DateTime.Now
            };

            _context.Rentals.Add(rental);
        }

        _context.SaveChanges();

        return Ok(customer);
    }

}

}

Why do we no use auto-mapper like we did for the other DTO's. Neither the lectures nor the solutions on github show creating a mapping profile. This is the only thing I can think of that may be causing the debugger to return null values.

Rendering customer index view

Hi @mosh-hamedani i have done all that has been explained in thread and i still this error when i remove the"@model Vidly.ViewModels.RandomMovieViewModel" from the Customer index view.

Line 32: {
Line 33:
Line 34: @Html.ActionLink(customer.Name,"Details","Customers", new {id=customer.Id},null)/td>
Line 35:
Line 36: }

kindly help out here, I am using VS 2015
the files and video is from Udemy and my ID on Udemy is taiwokaffo

JQuery not working for my VS 2013 Ultimate platform

Hi Mosh,

I'm currently working thru Section 7 of your Complete ASP.NET MVC 5 Course, and I'm having issues with implement the JQuery "DELETE" feature. I've inserted the button "DELETE" link on the table of my "Customers" Index View page as described

                <button data-customer-id="@customer.Id" class="btn-link js-delete">Delete</button> 

and has likewise added the prescribed id="customer" to the

tag

              <table id="customers" class="table table-bordered table-hover">

and finally, was attempting the first step of simply trying to get the "Confirm" pop up box to activate by adding the following JQuery script module to the bottom of my View page, after my table tag block

	@section scripts  
	{  
		<script>  
			$(document).ready(function () {  
				$("#customers .js-delete").on("click", function () {  
					confirm("Are you sure you want to delete this customer?");
				});  
			});  
		</script>  
	}  

and when I CTRL F5 and maneuver to the Customer Index page, I can see the "Delete" link on the table row detail, but when I click on it I get nothing, no reaction whatsoever. I've looked at my "Scripts" folder under the Solution Explorer, and it appears that I have all the required JQuery (Version 1.10.2) links added correctly. However do I need to refresh something or reinstall some part of my Visual Studio platform or what. Please help, thanks - I can't really proceed with the rest of the lesson until I get my JQuery scripts to respond on my page correctly.

ViewModel Error

Hello Sir,

Even though I have included required ViewModel in the View, there is an error as follows.

The model item passed into the dictionary is of type 'MoRe.ViewModels.NewCustomerViewModel', but this dictionary requires a model item of type 'MoRe.ViewModels.RandomMovieViewModel'.

image

image

I am unable to fix this error please let me know the solution.

jQuery Datatable

jQuery Datatable not​showing up..I mean using this $("#customers"). DataTable();
Has anyone passed this... please help

Web Api Post casting exception

Hello,
While posting a new customer using postman it gives the following Casting Exception

{
"message": "An error has occurred.",
"exceptionMessage": "Unable to cast object of type 'vidly.Dtos.CustomerDto' to type 'vidly.Models.Customer'.",
"exceptionType": "System.InvalidCastException",
"stackTrace": " at vidly.Models.Min18YearsIfAMemeber.IsValid(Object value, ValidationContext validationContext) in C:\Users\Dell\Documents\Visual Studio 2010\Projects\vidly\vidly\Models\Min18YearsIfAMemeber.cs:line 15\r\n at System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value, ValidationContext validationContext)\r\n at System.Web.Http.Validation.Validators.DataAnnotationsModelValidator.Validate(ModelMetadata metadata, Object container)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ShallowValidate(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable1 validators)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable1 validators)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateProperties(ModelMetadata metadata, ValidationContext validationContext)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.ValidateNodeAndChildren(ModelMetadata metadata, ValidationContext validationContext, Object container, IEnumerable`1 validators)\r\n at System.Web.Http.Validation.DefaultBodyModelValidator.Validate(Object model, Type type, ModelMetadataProvider metadataProvider, HttpActionContext actionContext, String keyPrefix)\r\n at System.Web.Http.ModelBinding.FormatterParameterBinding.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.HttpActionBinding.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"
}

the probleme is with [Min18YearsIfAMemeber] while checking the birthdate the type is customer there
not customerDto any solution please

Issue related with adding new rental details fetching from form by using ajax call

The auto complete feature works fine for me in both movies and customer fields. But when I submit the form I am getting a 500 network error (null pointer exception) for movieids. However, if I submit the data using postmaster calling the API, it works fine. I have attached the error code and the form data that I get as I submit the form.
formdataloaded

The moviesId array appear to be in a different format from the one we submit using API. Can someone help me with this?

Exception Error :An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Additional information: Unable to create a null constant value of type 'System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'. Only entity types, enumeration types or primitive types are supported in this context.

border of dropdown in mvc4 cannot be marked as red (.input-validation-error)

Hi guys,

I am not able to set the red border of the drop-down button, this is the config:

--View
@Html.DropDownListFor( m => m.Customer.MemberShipTypeId, new SelectList(Model.MemberShipTypes,"Id","Name"),"Select Membership Type" ,new{@Class = "form-control"})
@Html.ValidationMessageFor(m => m.Customer.MemberShipTypeId)

-- Site.css
select.input-validation-error {
border: 2px solid red;
}

-- Web browser is printing the element:
Select Membership Type Pays as You Go Monthly Quaterly Yearly

Any idea, why the drop-down button border cannot be marked as red.
Thanks

Two output file names resolved to the same output path

When i add migration , the name of the migration was same as the previous one. After that when i was update database the error was shown- Two output file names resolved to the same output path:"obj\Debug\Vidly.Migrations.AddMovieColomn.resources"
Plz resolve this issue

systemInvalidOperationException

var customers = _context.Customers.Include(c => c.MembershipType).ToList();

on exercise 3 when i click on custone tab it shows me error on this line

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.