viewmodel

Shielding nullable domain properties with ViewModel

末鹿安然 提交于 2019-12-03 17:08:00
I am using Entity Framework 4.0, and making use of POCO objects. When I populate POCO objects from the DB, I translate property values to my own Domain objects, which we can call my Model. Necessarily, whether or not the fields of my Model are Nullable depends on whether the value it maps to in the database comes from a NULL or NOT NULL column. I won't go into detail, but the values must be nullable in the DB, because a user can partially save a draft of the object before publishing it to the public. That being the case, I have several fields that are nullable. So let's say my model looks like

ViewModels with SelectList Design Decison

一个人想着一个人 提交于 2019-12-03 16:43:16
I have created a viewmodel public VMPosition { public VMPosition(){}//for model binder public VMPosition(int EmployeeID) { PositionStatusList = new SelectList(_repo.getStatuses); //populate other properties } public int CurrentPositionID { get; set; } public int EmployeeID { get; set; } public int CurrentPositionHistoryID { get; set; } public bool AddingNew { get; set; } public bool ClosingCurrent { get; set; } public string CurrentPosition { get; set; } public DateTime CurrentPositionStartDate { get; set; } public string ReasonForDeparture { get; set; } public SelectList PositionStatusList {

MVC4 C# Populating data in a viewmodel from database

蓝咒 提交于 2019-12-03 16:03:10
I have a viewmodel which needs data from two models person and address: Models: public class Person { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } public int Gender { get; set; } } public class Address { public int Id { get; set; } public string Street { get; set; } public int Zip { get; set; } public int PersonId {get; set; } } The Viewmodel is as such public class PersonAddViewModel { public int Id { get; set; } public string Name { get; set; } public string Street { get; set; } } I have tried several ways to get data into the viewmodel and pass

advice on architecting asp.net mvc applications

一个人想着一个人 提交于 2019-12-03 15:56:03
I've been using ASP.net MVC for about two years now and I'm still learning the best way to structure an application. I wanted to throw out these ideas that I've gathered and see if they are "acceptable" ways in the community to design MVC applications. Here is my basic layout: DataAccess Project - Contains all repository classes, LINQ-to-SQL data contexts, Filters, and custom business objects for non-MS SQL db repositories (that LINQ-to-SQL doesn't create). The repositories typically only have basic CRUD for the object they're managing. Service Project - Contains service classes that perform

Generic View Models?

不问归期 提交于 2019-12-03 15:29:10
I am wondering is it good practice to try to make a view that takes in a generic view model? I am wondering this because someone mentioned that he was anticipating to have to do lots of duplicate code unless he started to make a generic view and generic view model. So basically the views would be like just a set of controls. One view might have 2 controls(say a text-box and radio button) another view might have 50 controls on it. They will all have the same look and feel(it just grows by number of controls) . Basically he was thinking having a view model takes in the object(domain object)

AutoMapper - How to pass parameters into a Custom Resolver using ConstructedBy method?

十年热恋 提交于 2019-12-03 14:49:35
In my ASP.NET MVC 2 (RC) project - I'm using AutoMapper to map between a Linq to Sql class (Media) and a view model (MediaVM). The view model has a SelectList property for a drop down in the view. I have a custom value resolver to populate the SelectList property items from the db, but am wondering if there's a way to pass a couple values from the source model into the resolver (using ConstructedBy method?) to a) define the selected item and b) filter the items from the db. The source object gets passed into the custom resolver - but the resolver is used on several different view models with

Where should ASP.NET MVC 2 validation go: in the model or viewmodel classes?

有些话、适合烂在心里 提交于 2019-12-03 14:40:44
I am using automapper to map my models to viewmodel classes to pass to my view. My question really is where should the validation go? I was planning on using the MetaData decorations - a feature of mvc 2. But either in the model or viewmodel? Or in both places? Validation should be done minimum at the View Model because this is what you receive as action argument and contains the user input. You could also have validation at the model. My answer would be ViewModel because Model can change (for example from using Linq2SQL to EF). This way when you plug another Model you still have your

How should I communicate between ViewModels?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 14:38:51
I am using MVVM Light and have used the packaged messenger system to communicate between view models, however I have hit a bit of a dilemma! Basically when a user clicks on a customer record the corresponding view is opened and with it the CustomerViewModel is instantiated. At this point the CustomerViewModel requires the selected customers ID from the previous view model ( ViewAllCustomersViewModel ) so that it can get selected customers info which the view binds to (still following?). So initially my thought was too send that ID in a message from the ViewAllCustomersViewModel (where the

Do i need to create automapper createmap both ways?

匆匆过客 提交于 2019-12-03 14:25:39
问题 This might be a stupid question! (n00b to AutoMapper and time-short!) I want to use AutoMapper to map from EF4 entities to ViewModel classes. 1) If I call CreateMap<ModelClass, ViewModelClass>() then do I also need to call CreateMap<ViewModelClass, ModelClass>() to perform the reverse? 2) If two classes have the same property names, then do I need a CreateMap statement at all, or is this just for "specific/custom" mappings? 回答1: In AutoMapper you have a Source type and a Destination type. So

Building ViewModels based on nested Model Entities in WPF and MVVM Pattern

▼魔方 西西 提交于 2019-12-03 12:04:53
问题 I have a problem understanding how to build view models based on the following models (I simplified the models to be clearer) public class Hit { public bool On { get; set;} public Track Track { get; set; } } public class Track { public ObservableCollection<Hit> Hits { get; set; } public LinearGradientBrush Color { get; set; } public Pattern Pattern { get; set; } } public class Pattern { public string Name { get; set; } public ObservableCollection<Tracks> Tracks { get; set; } } Now, my problem