Code Monkey home page Code Monkey logo

contosouniversity's Introduction

ContosoUniversity

Contoso University sample re-done the way I would build it

contosouniversity's People

Contributors

jbogard avatar jhonnyslpz 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

contosouniversity's Issues

RedirectToActionJson

Hi Jimmy,

I have very straightforward create action in my controller. After creation I want to redirect to the edit action so the user can continue to edit the newly created item. However the RedirectToActionJson doesn't seem to work properly even though stepping through the code the edit action is being called but the redirection to the edit URL still indicates the create action (/SomeAction/Create) when I would have expected /SomeAction/Edit/[new id]

Could it be something to do with some StructureMap "magic" around ending the request (StructureMapScopeModule) because I'm using Autofac?

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateEdit.Command command)
{
    var id = _mediator.Send(command);
    return this.RedirectToActionJson(c => c.Edit(new CreateEdit.Query { Id = id }));
}

public ActionResult Edit(CreateEdit.Query query)
{
    var model = _mediator.Send(query);
    return View("CreateEdit", model);
}

Add .vs folder to gitignore

Ought to do some cleanup and remove that application.hosts file before so it won't get pulled with future clones.

ViewModels Folder?

Sticking with the idea of eliminating layers and creating slices:

The following two files are never used and can be deleted.

AssignedCourseData.cs
InstructorIndexData.cs

The EnrollmentDateGroup class defined in EnrollmentDateGroup.cs could be moved into the Home/UiController class given that is the only scope in which it is being used other than the About.cshtml file, which should be updated to

@model IEnumerable<ContosoUniversity.Features.Home.UiController.EnrollmentDateGroup>

Then the entire ViewModel Folder can be eliminated. The concept of the Viewmodels are now included in Features.

Refill model after being submitted with errors.

Hello,

I have been looking at Contoso University and I have a question:

How do you deal with refilling the model helper properties after being submitted with errors?
I am talking about filling SelectLists or the data which the SelectLists depends on?

Thank You,
Miguel

Use of Automapper for DTO -> Entity

I was under the impression that you (@jbogard) was rather against the notion of using Automapper to map from DTOs back into an Entity/Domain object.

However, this sample is filled with that usage, where you take in a Command object (a DTO) and map it to the EF entity.

Why did you use this approach? Just for the sake of "learning". Would you actually do it this way in "real life"?

HtmlTags v4 support

FormBlocks do not work with v4 of HtmlTags. It spits out raw HTML instead of rendered labels and controls.

roundhouse missing assembly reference

Error 970 The type or namespace name 'roundhouse' could not be found (are you missing a using directive or an assembly reference?) g:\Plastic\JBogardContosoUniversity\src\IntegrationTests\LocalDbFactory.cs 7 11 IntegrationTests

Generic Notifications

Hello, I am using Contoso University and I require notifications for individual modules, however, this notification will be similar throughout the application, so we are wondering if we can create one generic notification that multiple modules can share?

How would you implement authorization business logic?

For example, if the user should only be able to view their own courses, how do you pass their identity back to the command or query handler? Do you just append it to the command/query prior to calling the handler like so?

public ViewResult Index(Index.Query query)
{
    query.UserId = User.Identity.Name;

    var model = _mediator.Send(query);

    return View(model);
}

My current use case is that a user has a Scope property that denotes the highest level of organizational data they can access. This is a hierarchical structure going from Enterprise > Region > Site. If they have enterprise, they can filter on any site, if they only have Region 1, they can only filter on sites under Region 1, if it is Site 3, only Site 3 data is available.

ASP.NET Core

Hi Jimmy, Would you have an idea of how to convert this code to use the ASP.NET Core dependency injection code?

private static IElementGenerator<T> GetGenerator<T>(T model) where T : class
        {
            var library =
                StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<HtmlConventionLibrary>();
            return ElementGenerator<T>.For(library, t => StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance(t), model);
        }

Pull Requests

Will you accept pull requests to migrate the other feature folders to MediatR as you have done with Departments?

And Happy Birthday!

Unable to add a new department

I get an error “The highlighted fields are required to submit this form” which is found in the javascript function showSummary of \js\site.js (line 42).

I don’t know enough of JavaScript to figure out how to debug it, nor do I know enough of your approach to building ASP.Net MVC web apps (but am definitely trying to learn as it looks very cool)

department create error administrator required by it really is

Thanks,
John Marsing

Dispatching messages from command handler after committing DB transaction

I'm curious to understand, given this implementation, how you recommend handling the scenario where a message (e.g. queue) needs to be dispatched, ala domain events style, from a command handler, but only after the transaction is committed.

The DB transaction is being committed or rolled back via the MVC action filter's OnActionExecuted, which uses service locator to get the DbContext, and call the CloseTransaction. In other words, the transaction commit is being done outside the command handler. However, I'd like to dispatch an event message from the command only when the transaction is committed successfully, and from the command handler, I have no way of knowing when the transaction is committed.

Any thoughts on this?

Question: indexer on foreach

Hi,

I have question about the syntax you used in some of the Index pages. For instance, Course - Index

There is a foreach loop that creates a table row for each Course, but instead of using the item variable you use an indexer to access the properties of that Course.

@Html.Display(modelItem => modelItem.Courses[i].CourseID)

What is the reason for doing it like this?

Thanks for helping me out.

Autofac?

for example what would this look like in AF?

private static IElementGenerator<T> GetGenerator<T>(T model) where T : class
{
      var library = StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<HtmlConventionLibrary>();
      return ElementGenerator<T>.For(library, t => StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance(t), model);
}

FxCop CA1034

Hey Jimmy,

I've been using MediatR on a couple projects for the last 6 months and love it.

I've seen in many of your examples that you use nested types often for encapsulating your commands/queries. FxCop flags the CA1034 warning when using this pattern. Is that CA1034 rule anything we should be concerned about when using MediatR?

Thanks!

Should features own the domain model as well?

@jbogard, you've written that the domain model could receive a command for changes (and here), but I've not seen that combined with MediatR usage. In this project you use AutoMapper to apply the message externally per-property, and the models classes don't receive message objects through functions on them.

Does it make sense to be receiving the IAsyncRequest derived commands/requests in the domain model?

In my applications, I keep the domain models in a separate assembly so they can be shared with back-end asynchronous processes that don't run in the web context.

Should the non-web portion of the features (request, handler, response) live in the domain model assembly? Should there be domain model specific commands that are mapped to when needed from the IAsyncRequest commands after validation; keeping the features in the web project?

Thanks in advance.

FormBlocks

Hi Jimmy, I've been reading you articles about templates and like the way you did the FormBlock code. However, I can't seem to get a textarea to display. I've added [DataType(DataType.MultilineText)] to my model property but it seems to ignore it. Should I extend your example and create a specific "TextAreaBlock" or something else?

Use of Attribute Routing possible?

I'm adapting this pattern in a test app I'm developing and I'm wondering if it's possible to use MVC's attribute routing? I'm not having much luck, I just get a 404 if I remove the convention-based routing. Any ideas?

Why is MvcTransactionFilter related to SchoolContext ?

MvcTransactionFilter works only for SchoolContext.

 public class MvcTransactionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // Logger.Instance.Verbose("MvcTransactionFilter::OnActionExecuting");
            var context = StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<SchoolContext>();
            context.BeginTransaction();
        }

    ...
}

Is there a way to make MvcTransactionFilter work for multiple datacontexts ?
By the way the multiple contexts may want to share the same transaction scope.

Basic DropDownList

Hi Jimmy,

I'm trying to create a select list that's not bound to EF. I want to have something like this:-

public static HtmlTag Select<T>(this HtmlHelper<T> helper, Expression<Func<T, object>> expression)
            where T : class
        {
            var generator = GetGenerator(helper.ViewData.Model);
            return generator.SelectFor(expression, "Select");
        }

But I can't figure out how to do it. Would you by chance have a spare minute to help?

Routes to controller actions are no longer case insensitive

Not sure what causes this, but likely due to having a custom controller factory, the routes are no longer case insensitive.

For example, if you create a /Features/Foo/UiController, with a Bar action, and request it via URL /foo/bar, this will return 404, but requests to /Foo/Bar work.

Areas

How would you go about adding support for Areas? I think it would make sense for a folder structure similar too

  • Areas
    • AreaName
      • Features
        • Foo
          • Index.cshtml
          • UiController.cs

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.