Category Archives: Entity Framework

Entity Framework

[RESOLVED]Adding a new field in Register Page.Storing Data in DataBase

Hi, 

 I’m new to this,To start with i downloaded a wingtip web asp.net sample. I want to include a new field ‘EMPLOYEEID" in register page and store the data in AspNetUsers database table. I have created the field in Register page and a new column in database(Aspnetuser.EmployeeID)
.

What are the changes to be done in code to add the user data to database through register page.

//For now I have done something like this: IN register.aspx page I changed this(in BOLD)

protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var user = new ApplicationUser() { UserName = Name.Text, Email = Email.Text , EmployeeID = EmployeeID};
IdentityResult result = manager.Create(user, Password.Text);

Hi harshilshah,

Thanks for your post.

Based on my understanding ,you want to add extra information in  AspNetUsers database table?

Firstly you need to install these two packages:- Microsoft.Aspnet.Identity.Core

This package contains the core interfaces of ASP.NET Identity.Microsoft.Aspnet.Identity.EntityFramework

This package contains the implementation of ASP.NET Identity System which works with Entity Framework Code First. This means that if we use this package then we can store information in a SQL Server database. Also we can easily plug other databases if we
wanted.and then updated your IDE

Secondly,Enable Entity Framework Code First Database Migrations.Thirdly,Add new properties

Fourthly,Add New Migration

Fifthly,Update RegisterViewModel

and then Update Register View Page and Update Account Controller’s Register action (Post Version)

Details information:

#Customize User’s Profile in ASP.NET Identity System

http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html

Hope this can be helpful.

Best Regards.

Eileen

[RESOLVED]Bind IDictionary List to MVC WebGrid

I’m dont know how to bind an IDictionary list to a MVC WebGrid. This is what I have so far

 public List<IDictionary> GetAddress()
        {
            List<IDictionary> names = new List<IDictionary>();
        //List<string> names = new List<string>();
            using (MVCDBEntities example = new MVCDBEntities())
            {
                var Uus = from U1 in example.Users where U1.Name != null select U1;
                names = Uus.OfType<IDictionary>().ToList();
            }
            return names;
        }

I now need to some how bind  this to a webgrid, how would I achieve this ?

Hi,

taken from

http://forums.asp.net/t/1719060.aspx?Binding+MVC3+webgrid+from+DataTable+AsEnumerable+:

Model method:

public List<IDictionary> FetchEmployeeDetails()
         {
             DataSet dsEmployee = new DataSet();
             DbCommand dbCmd = m_DbAccess.SqlDb.GetStoredProcCommand("Test_FetchEmployeeDetails");
             dbCmd.CommandType = CommandType.StoredProcedure;
             dsEmployee = m_DbAccess.SqlDb.ExecuteDataSet(dbCmd);

             return ConvertToListDictionary(dsEmployee.Tables[0]);
         }

Controller Code:

public ActionResult FetchDataForGrid()
         {
             EmployeeModels modelObject = new EmployeeModels();
             var resultSet = modelObject.FetchEmployeeDetails();
             return View(resultSet);
        }

View Code:

@using System.Dynamic
 @model List<System.Collections.IDictionary>
 @{
     var result = new List<dynamic>();

     foreach (var emprow in Model)
     {
         var row = (IDictionary<string, object>)new ExpandoObject();
         Dictionary<string, object> eachEmpRow = (Dictionary<string, object>)emprow;

         foreach (KeyValuePair<string, object> keyValuePair in eachEmpRow)
         {
             row.Add(keyValuePair);
         }
         result.Add(row);
     }
     var grid = new WebGrid(result);
 }

 @if (@Model != null)
 {
     @grid.GetHtml(tableStyle: "grid", headerStyle: "head", alternatingRowStyle: "alt");
 }

Grz, Kris.

Thanks for the reply, I am just getting an error with the IDictionary list anyways thanks for your time.  Is there anyway you can just use a asp.net Gridview control with something like this with the entity framework ? As binding data to a webgrid in mvc
is a joke, so much extra work, in php its easier than this

Hi,

you can’t really make use of the gridview in MVC.

What you can do, and what I did in the past, is make use of jqGrid and bind the grid client side. There are also commercial tools for this like KendoUI and others.

Grz, Kris.

How to iterate model and save to database?

How can you iterate through a single model and save it multiple times so that a new record/row is created in the database?

For example I have an application form and I wish to create multiple applications using the same details but for each application I will change the applicant.

I have the following controller action to which attempts to achieve this:

public ActionResult Create([Bind(Prefix = "Application")]Application application, FormCollection collection)
{

List<string> selectedEmployees = new List<string>();

// Application.EmpIDs is a multiselect drop down list
if (collection["Application.EmpIDs"] == null)
{
	ModelState.AddModelError("Employee", "Please select an employee");
}
else
{
	selectedEmployees.AddRange(collection["Application.EmpIDs"].Split(',').ToList());
}



if (ModelState.IsValid)
{

   
   foreach (var item in selectedEmployees)
   {
	// Add emp id
	application.EmpID = Convert.ToInt32(item);
                           
                            
	// Add Application
	_repository.AddApplication(application);

	// Persist changes back to database
	_repository.Save();

	

    }
}

//...more stuff

}

however i end up with the following error message:

An object with the same key already exists in the ObjectStateManager. The existing object is in the Modified state. An object can only be added to the ObjectStateManager again if it is in the added state.

It sounds like the object you are looking for already exists within your context. Have you tried removing the AddApplication() call and just calling the Save() (or SaveChanges()) method on it’s own? If Entity Framework is tracking your elements,
then it will track changes (such as new or updated property values) which will be saved to the database when the Save method is called :

// Add emp id
application.EmpID = Convert.ToInt32(item);
                           
// Persist changes back to database
_repository.Save();

You might also want to consider taking a look at the data within your database to be sure that you don’t have any issues or duplicate keys (or any logical issues that could cause that to occur).

the AddApplication() call simply updates some additional property values. The full method is below:

public void AddApplication(Application application)
{
            application.StatusID = 1;
            application.CreatedDate = DateTime.Now;
            application.LastModifiedDate = DateTime.Now;
            application.StatusDate = DateTime.Now;

            _entities.Applications.AddObject(application);

}

there should be no issues with the database becuase each application has an autoincrement primary key.

ok i’ve managed to get this working by adding the following line after the save method:

// Detach the entity from object context
_repository.Detach(application);

However I need get the ids of all the newly added applications. I have added the following list below the save method but all i get added into this list is the first application multiple times hence i end up with the same application id.

// Persist changes back to database
_repository.Save();

// create list of applications added to reference new application ids
// this is basically a list  List<Application> applicationsSubmitted = new List<Application>();
applicationsSubmitted.Add(application);
// Detach the entity from object context 
_repository.Detach(application);

[RESOLVED]How to Post with foreign keys

public List<Job> PostNewJob(Job newJob)
        {
            Job job = new Job();

            job.JobId = newJob.JobId;
            job.JobNumber = newJob.JobNumber;
            job.JobName = newJob.JobName;
            job.JobDescription = newJob.JobDescription;
           
            db.Jobs.Add(newJob);
            db.SaveChanges();

            return db.Jobs.ToList();
        }

 public class Job
    {
        public Job()
        {
            this.Customers = new HashSet<Customer>();
            this.ChangeOrders = new HashSet<ChangeOrder>();
        }
        public int JobId { get; set; }
        public int JobNumber { get; set; }
        public string JobName { get; set; }
        public string JobDescription { get; set; }

        public virtual ICollection<Customer> Customers { get; set; }
        public virtual ICollection<ChangeOrder> ChangeOrders { get; set; }
    }


public List<Customer> PostNewCustomer(Customer newCustomer)
        {
            Customer customer = new Customer();

            customer.CustomerId = newCustomer.CustomerId;
            customer.CustomerName = newCustomer.CustomerName;
            customer.CustomerPhoneNumber = newCustomer.CustomerPhoneNumber;
            customer.CustomerFaxNumber = newCustomer.CustomerFaxNumber;
            customer.JobId = newCustomer.JobId;

            db.Customers.Add(newCustomer);
            db.SaveChanges();

            return db.Customers.ToList();
        }

 public class Customer
    {

        public int CustomerId { get; set; }
        public string CustomerName { get; set; }
        public Int64 CustomerPhoneNumber { get; set; }
        public Int64 CustomerFaxNumber { get; set; }

        public int? JobId { get; set; }
    }


 $scope.submitJob = function () {
        var id = $scope.currentItem.JobName
        var data = {
            JobId: $scope.currentItem.JobId,
            JobNumber: $scope.currentItem.JobNumber,
            JobName: $scope.currentItem.JobName,
            JobDescription: $scope.currentItem.JobDescription
            
            
        }
        $http.post('/api/apiJob/PostNewJob', data).success(function (data, status, headers) {
            console.log(data);
               $scope.PrintPreviewModal();
               window.top.location.reload();
            
        });
 };

  <form ng-submit="submitJob()" enctype="multipart/form-data">
                            <fieldset>
                                <div>
                                    <div class="inline-fields">
                                        <label>Number:</label>
                                        <input ng-model="currentItem.JobNumber" type="text">

                                        <label>Job Name:</label>
                                        <input ng-model="currentItem.JobName" type="text">
                                        <label>Customer:</label>
                                        <input type="text" ng-model="currentItem.CustomerName">
                                    </div>
                                    <div class="inline-fields">
                                        <label>Address:</label>
                                        <input ng-model="currentItem.CustomerAddress" type="text">
                                    </div>
                                    <div class="inline-fields">
                                        <label>City:</label>
                                        <input ng-model="currentItem.CustomerCity" type="text">

                                        <label>St:</label>
                                        <input ng-model="currentItem.CustomerState" type="text">

                                        <label>Zip:</label>
                                        <input ng-model="currentItem.CustomerZipcode" type="text">

                                <input type="submit" value="Save" />

                            </fieldset>
                        </form>

I am trying to change how I post and update my primary class JOB. Previously I was using the Customer Class as a List and I was storing the JOB Customer information in the Job class itself. The problem with this was If I went to go update a Customers information
in the Customer List I would have to go to every Job that has that Customer and Manually update everyone separately. So I am unsure how to do this. When I am creating a New Job how do I  Connect the appropriate Customer with that Job? I am already doing this
with another class called ChangeOrder but the difference is the Job has to be already been created before I can make that Post.. And also, the Customer can be assigned to multiple Jobs. So How does the foreign key work with this? How can you have a Customer
with multiple foreign keys "JobIds" attached to it?

What you are looking is a many to many relationship. Please take a look at this article in MSDN magazine

Handle Many-to-Many Relationships in Entity Framework and ASP.NET MVC

ok, so I created a linking table. What am I doing wrong? Here is what is coming back from the database

 {$id:1, JobCustomerId:1, JobId:1, Job:null, CustomerId:2, Customer:null}
$id: "1"
Customer: null
CustomerId: 2
Job: null
JobCustomerId: 1
JobId: 1

public class JobCustomer
    {
        public int JobCustomerId { get; set; }
        public int JobId { get; set; }
        public virtual Job Job { get; set; }
        public int CustomerId { get; set; }
        public virtual Customer Customer { get; set; }
    }
public class Job
    {
       
        public int JobId { get; set; }
        public int JobNumber { get; set; }
        public string JobName { get; set; }
        public string JobDescription { get; set; }

        public ICollection<JobCustomer> JobCustomers { get; set; }
       
    }
public class Customer
    {

        public int CustomerId { get; set; }
        public string CustomerName { get; set; }
        public Int64 CustomerPhoneNumber { get; set; }
        public Int64 CustomerFaxNumber { get; set; }

        public ICollection<JobCustomer> JobCustomers { get; set; }
      }
public List<JobCustomer> GetJobs()
        {
            List<JobCustomer> jobs = new List<JobCustomer>();
             jobs = db.JobCustomers
                .ToList();
            return jobs;
        }

Hi texas697,

You don’t need to create a link table manually, the EF will create it. For the link table, it doesn’t have the entity field, just the keys of these entities.

For your code, the fluent API would be like this:

modelBuilder.Entity<Job>() 
    .HasMany(j => j.Customers) 
    .WithMany(c => c.Jobs) 
    .Map(m => 
    { 
        m.ToTable("JobCustomer"); 
        m.MapLeftKey("JobId"); 
        m.MapRightKey("CustomerId"); 
    });
public class Job
    {
       
        public int JobId { get; set; }
        public int JobNumber { get; set; }
        public string JobName { get; set; }
        public string JobDescription { get; set; }

        public ICollection<Customer> Customers { get; set; }
       
    }
public class Customer
    {

        public int CustomerId { get; set; }
        public string CustomerName { get; set; }
        public Int64 CustomerPhoneNumber { get; set; }
        public Int64 CustomerFaxNumber { get; set; }

        public ICollection<Job> Jobs { get; set; }
      }

More information, please refer to:

# Configuring a Many-to-Many Relationship

http://msdn.microsoft.com/en-in/data/jj591620.aspx#ManyToMany

Best Regards

Starain Chen

that sure does make things easier. Now what if I have additional classes that need to be linked to Job? How would the modelBuilder look? Do i put this in my IdentityModels? If this is the correct way of doing it, I did do a migration without errors. The
tables in the sql where created. But How Do I query the information from my project? I went through the JobApi but the data for Customers, ChangeOrders, etc… came back null. 

 public class ApplicationUser : IdentityUser
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public bool? Hidden { get; set; }
        public string UserEmail { get; set; }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()

            : base("DefaultConnection", throwIfV1Schema: false)
        {
            this.Configuration.LazyLoadingEnabled = false;
            this.Configuration.ProxyCreationEnabled = false;

        }
        public DbSet<Job> Jobs { get; set; }

        public DbSet<Employee> Employees { get; set; }
        public DbSet<Customer> Customers { get; set; }
        public DbSet<ChangeOrder> ChangeOrders { get; set; }
        public DbSet<JobType> JobTypes { get; set; }
        public DbSet<GeoArea> GeoAreas { get; set; }
        public DbSet<JobClass> JobClasses { get; set; }

        protected override void OnModelCreating
       (DbModelBuilder modelBuilder)
        {
base.OnModelCreating(modelBuilder); modelBuilder.Entity<Job>() .HasMany(j => j.Customers) .WithMany(c => c.Jobs) .Map(m => { m.ToTable("JobCustomer"); m.MapLeftKey("JobId"); m.MapRightKey("CustomerId"); }); modelBuilder.Entity<Job>() .HasMany(j => j.ChangeOrders) .WithMany(c => c.Jobs) .Map(m => { m.ToTable("JobChangeOrder"); m.MapLeftKey("JobId"); m.MapRightKey("ChangeOrderId"); }); modelBuilder.Entity<Job>() .HasMany(j => j.GeoAreas) .WithMany(c => c.Jobs) .Map(m => { m.ToTable("JobGeoArea"); m.MapLeftKey("JobId"); m.MapRightKey("GeoAreaId"); }); modelBuilder.Entity<Job>() .HasMany(j => j.JobTypes) .WithMany(c => c.Jobs) .Map(m => { m.ToTable("JobJobType"); m.MapLeftKey("JobId"); m.MapRightKey("JobTypeId"); }); modelBuilder.Entity<Job>() .HasMany(j => j.JobClasses) .WithMany(c => c.Jobs) .Map(m => { m.ToTable("JobJobClass"); m.MapLeftKey("JobId"); m.MapRightKey("JobClassId"); }); } }

 public class Job
    {
       
        public int JobId { get; set; }
        public int JobNumber { get; set; }
        public string JobName { get; set; }
        public string JobDescription { get; set; }

        
        public ICollection<Customer> Customers { get; set; }
        public ICollection<ChangeOrder> ChangeOrders { get; set; }
        public ICollection<GeoArea> GeoAreas { get; set; }
        public ICollection<JobClass> JobClasses { get; set; }
        public ICollection<JobType> JobTypes { get; set; }
    }

Hi texas697,

Your code is right.

To load the related entities, we could use Include method.

For example:

var data =db.Jobs.Include("Customers");

Best Regards

Starain Chen

Webgrid Questions

I am wanting to create a webpage that has a webgrid where you can select a row and it will show the details of that row below the webgrid for editing. Could someone provide an example of how to do this?

I wrote and article about doing this using the Web Pages framework. You can adapt it to MVC: http://www.mikesdotnetting.com/Article/168/The-WebGrid-Helper-Making-Selections

Thank you for the reply. I found that article very helpful. Except when you got to this part:

@if(grid.HasSelection){
    var book = grid.SelectedRow;
    @RenderPage("~/Partials/EditBook.cshtml", new { Book = book } )
}

How did you get the value for book? I do not see anywhere in the code you gave where that is located. 

The second parameter of the RenderPage method takes an anonymous object representing data to be passed to the partial. In this case, the value (book, with a lower case b) is the SelectedRow property of the grid. The SelectedRow property is a dynamic
object whose properties are made up from the column names. So book is a dynamic object with BookId, Title, Description etc properties.  This is passed to the Partial’s
PageData property (also accessible via the dynamic Page property). So in the partial, the Id of the book is obtained like this:

var bookid = Page.Book.BookId;

Thank you for the response. Sorry for my delayed response. But I am trying to do this in a MVC format, so I would not want to access the data from a webpage. How do you pass that value to a controller to then access the data?

You still need to pass the data to the View. In MVC, you get the data within the controller and pass it to the view either as a strongly typed model or in ViewBag. Then you will bind the model to the WebGrid in the View. 

I am trying your method and actually querying the database from the partial view but I am using Entity Framework to access the database and I do not have the functionality do the Database.Open command. Again is there a way to pass the selected value from
the webgrid to my controller and then render that partial page by a strongly typed Edit page?

[RESOLVED]MVC & External Controllers

I am new to MVC so this is a basic question. I have the following two projects:

1) A Web API that was generated with the PLINQO-EF (LINQ to SQL for Entity Framework) template for CodeSmith.

2) An MVC application using Kendo.

Project 2) needs to use the controllers which reside in project 1). My question is how to use the controllers from project 1) without moving the controllers to project 2), i.e. combining the projects.

Note that I can call the Web API from project 2) via PostAsJsonAsync. However, I want to be able to use constructs like

<siteMapNode controller="grid" action="index" title="my title" area="myarea"/>

hufaun

However, I want to be able to use constructs like

<siteMapNode controller="grid" action="index" title="my title" area="myarea"/>

And why you can put this construct?

You should use your other project as an external url in your sitemap

<siteMapNode
title="my
title
"
url="/virtualdirectory/myaread/grid/index"
/>

Hi hufaun,

Since these projects are independent of each other, in my opinion, you can’t able to access the Web API directly, you need to call it through
HttpClient class.

For the siteMapNote, you need to specify the absolute URL. If these projects are under a website, you could refer to
pprasannak’s solution.

Best Regards

Starain Chen

[RESOLVED]How to get started with ASP.NET MVC ?

I’ve learned ASP.NET 2-3 years ago and I’d made some projects on ASP.NET. Now It feels like I can improve them little bit. As I’ve some 15 days free, So I was thinking to learn something new and use it in my old projects.

Actually there are some areas in my projects where I’ve to design new tools which is not possible with ASP.NET alone. For example I’m having "Virtual Classroom Project" and there is a tool called "White Board" which allow Professor to explain the things
to students. I was going to start learning Silverlight then some of my friends suggested me of ASP.NET MVC.  I’m new to ASP.NET MVC and don’t know anything about it.

How it is different from ASP.NET ?
What features does it offers ?
Whats the future of it ?
How much ASP.NET MVC coding is different from ASP.NET ?
How much time will it take to learn ASP.NET MVC ?

I’d suggest to spend 1 hour of 15 days to google all 5 questions.

Spend an hour or two and walk through this beginner’s tutorial:

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-1

this tutorial covers most of the basics for MVC.  Please note that this tutorial is slightly dated — I believe it’s more for MVC 3 than 5, however the same principles still apply.

MVC Resources

The Getting Started MVC area on this site is a great place to start as well if you want to start learning MVC outside of a book environment. It will cover just about everything that you would need to build complete applications
and it is written by experts that apply best practices to help you build good habits for future applications.

One of the most well regarded and complete MVC-based tutorials would be the ASP.NET MVC Music Store tutorial, which you can find under the MVC section of this site. However, any
of the tutorials on this site
 should be great stepping stones to get you building your own complete MVC applications in no time.

You can find a few other resources listing off countless other MVC-based tutorials below: 

or the following more architecturally based examples :

I would definately recommend the MVC Music Store Tutorial as well as the other ones available on this site (ASP.NET) and if you are still looking for more information after that, check out some of the other links I provided. If you are still looking
for some additional tutorials or other MVC based projects, you might want to dig around on open-source sites like github and Codeplex and search for a bit more complex sites and projects.

Regarding Your Questions

22990atinesh

How it is different from ASP.NET ?

Technically, ASP.NET is still based on the same framework as Web Forms (which I am assuming that you are referring to in this context). MVC just provides a different pattern and approach to developing your applications. It is patterned after the
web and thus is stateless (so you don’t have a ViewState or any Controls). Due to it’s nature, it lends itself well to separating your concerns (all of your Presentation-related code is within the Views, your business logic will be within your
models and your Controllers will handle your data access
).

22990atinesh

What features does it offers ?

It doesn’t necessarily "offer" any newer features. Some might argue that it can be tested more easily than Web Forms (if you actually are one of the people out there writing tests consistently). I personally find it to be much simpler than Web Forms in a
very "bare-bones" sense.

22990atinesh

Whats the future of it ?

Bright. MVC has really taken off since it’s release and is continuing to gain more and more steam for developing Microsoft Web Applications. Web Forms is still completely relevant and will continue to play a major role, but MVC is certainly catching up.

It’s worth learning.

22990atinesh

How much ASP.NET MVC coding is different from ASP.NET ?

As I mentioned earlier, there are quite a few learning curves associated with it. The lack of "Controls" can be tough for those migrating from Web Forms as can the lack of a state. Since controls don’t exist, it requires developers to be much more comfortable
with using pure HTML and Javascript to accomplish many of the things that their controls did previously. 

22990atinesh

How much time will it take to learn ASP.NET MVC ?

This is something that depends entirely on you and how quickly you can understand the different components of an MVC application and how they work together. The tutorials mentioned earlier should help with this.

22990atinesh

there is a tool called "White Board" which allow Professor to explain the things to students

SignalR is a good fit for your whiteboard application. Please take look at these posts

Online
Whiteboard using HTML5 and
SignalR

A SignalR Whiteboard

22990atinesh

As I’ve some 15 days free, So I was thinking to learn something new and use it in my old projects.

I recommend learning AngularJS. It is getting more traction now-a-days. You can use MVC/WebAPI with AngularJS

Rion Williams

MVC Resources

The Getting Started MVC area on this site is a great place to start as well if you want to start learning MVC outside of a book environment. It will cover just about everything that you would need to build complete applications
and it is written by experts that apply best practices to help you build good habits for future applications.

One of the most well regarded and complete MVC-based tutorials would be the ASP.NET MVC Music Store tutorial, which you can find under the MVC section of this site. However, any
of the tutorials on this site
 should be great stepping stones to get you building your own complete MVC applications in no time.

This is something that depends entirely on you and how quickly you can understand the different components of an MVC application and how they work together. The tutorials mentioned earlier should help with this.

Thanx for help Now I can start learning ASP.NET MVC.

How is ASP.NET Web Pages, Is it better than ASP.NET MVC. Is it possible create tools that I asked for with ASP.NET Web pages. 

ASP.NET Web pages are completely different than MVC.If you are strong with HTML concepts you may be able to learn it quickly.

22990atinesh

How is ASP.NET Web Pages, Is it better than ASP.NET MVC. Is it possible create tools that I asked for with ASP.NET Web pages. 

Neither are necessarily better than the others, they are different patterns / technologies that both can be used to create Web Applications. Web Pages can be thought of as a more entry-level technology (not to say that it cannot be used to build complex
Web Applications
) whereas MVC encompasses a much larger set of libraries and in general more complex (which might be overkill for something as simple as a Web Site).

Both can create Web Applications, which is ultimately what your goal is, so either might be worth exploring as an option.

Rion Williams

22990atinesh

How is ASP.NET Web Pages, Is it better than ASP.NET MVC. Is it possible create tools that I asked for with ASP.NET Web pages. 

Neither are necessarily better than the others, they are different patterns / technologies that both can be used to create Web Applications. Web Pages can be thought of as a more entry-level technology (not to say that it cannot be used to build complex
Web Applications
) whereas MVC encompasses a much larger set of libraries and in general more complex (which might be overkill for something as simple as a Web Site).

Both can create Web Applications, which is ultimately what your goal is, so either might be worth exploring as an option.

I’ve tried ASP.NET MVC, It’s a totally new concept. I’ll learn it in the future. For now I just want to create a "White Board tool" which should be capable of displaying PPT, PDF, have Simple Drawing tool and a chat box. Can I do it with the help of HTML
5 + Jquery + CSS

22990atinesh

I’ve tried ASP.NET MVC, It’s a totally new concept. I’ll learn it in the future. For now I just want to create a "White Board tool" which should be capable of displaying PPT, PDF, have Simple Drawing tool and a chat box. Can I do it with the help of HTML 5
+ Jquery + CSS

You’ll likely need to use some kind of server-side code in order to properly retrieve your various types of files (unless they are explicitly stored in the same directory as your project and you would be accessing them through links). Additionally,
most browsers are not going to be able to "display" files like PowerPoint natively, you’ll need to look into a library as a way to present these within the browser (although there are other
ways to embed a PowerPoint presentation within your web application
).

Finally, a drawing tool shouldn’t be too out of reach as it’s very commonly implemented using the HTML <canvas> element along with a bit of Javascript / jQuery. If you search around for it, you shouldn’t have too much trouble finding a simple HTML5 Drawing
implementation. There are quite a few "it depends" answers related to a project like this and I am sure that you should be able to accomplish something like it using either a pure HTML5 / Javascript implementation or one that leverages ASP.NET (either
Web Pages or MVC
).

zing!

22990atinesh

Can I do it with the help of HTML 5 + Jquery + CSS

Have you looked at my earlier links?

Online
Whiteboard using HTML5 and
SignalR

A SignalR Whiteboard

Let’s see videos to understand about MVC .NET. You can understand some things

http://youtu.be/lG49gPy-hG0

http://youtu.be/ZKYlK4RFa1I

http://youtu.be/-ZdgU8Hngxw

Hi,

Please use below link to know about basic MVC history, basic, business section are same what we had been used in ASP.Net. 

http://www.asp.net/mvc

http://mvc4beginner.com/Tutorial/

http://msdn.microsoft.com/en-us/vs2010trainingcourse_aspnetmvc3razor.aspx

http://20fingers2brains.blogspot.com/2014/01/introduction-to-aspnet-mvc-3.html

http://www.microsoftvirtualacademy.com/training-courses/introduction-to-asp-net-mvc

Please don’t rush to learn short time, please work out what you learn day by day.

Thanks,

Jai.

Rion Williams

22990atinesh

I’ve tried ASP.NET MVC, It’s a totally new concept. I’ll learn it in the future. For now I just want to create a "White Board tool" which should be capable of displaying PPT, PDF, have Simple Drawing tool and a chat box. Can I do it with the help of HTML 5
+ Jquery + CSS

You’ll likely need to use some kind of server-side code in order to properly retrieve your various types of files (unless they are explicitly stored in the same directory as your project and you would be accessing them through links). Additionally,
most browsers are not going to be able to "display" files like PowerPoint natively, you’ll need to look into a library as a way to present these within the browser (although there are other
ways to embed a PowerPoint presentation within your web application
).

Finally, a drawing tool shouldn’t be too out of reach as it’s very commonly implemented using the HTML <canvas> element along with a bit of Javascript / jQuery. If you search around for it, you shouldn’t have too much trouble finding a simple HTML5 Drawing
implementation. There are quite a few "it depends" answers related to a project like this and I am sure that you should be able to accomplish something like it using either a pure HTML5 / Javascript implementation or one that leverages ASP.NET (either
Web Pages or MVC
).

Hello Rion William,
I’ve read SignalR articles from official ASP.NET website. Its a very cool and easy concept. A simple "Chat box" App requires only few lines of code (hardly 7-8 lines of code after adding the SignalR library) and its quite self explanatory. And Ya HTML 5 canavas
is also easy way to create white board. I can combine these two to make a simple White board tool, But I’m trying to build a more advanced white board tool with more flexibility and more featues. Please see this post

http://forums.asp.net/t/2012233.aspx?What+you+can+and+can+not+do+with+ASP+NET+SignalR+

Pro ASP.NET MVC 5

How to show all data from three relationship forignkey tables in index action with my model

I have created 3 tables by Code first approach using EF MVC 4

  • between Album table and Photo table I have one to many relationship
  • between Photo table and Tag table I have one to many relationship

These are my tables:

[Table("Tag")]
    public class Tag
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int tagid { get; set; }
        public string tagname { get; set; }
        public int photoid { get; set; }

        public virtual Photo Photo { get; set; }
    }

[Table("Album")]
    public class Album
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int albumid { get; set; }
        public string albumname { get; set; }

        public virtual ICollection<Photo> Photos { get; set; }
    }

[Table("Photo")]
    public class Photo
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int photoid { get; set; }
        public string photoname { get; set; }
        public int albumid { get; set; }   
        
        public virtual Album Album { get; set; }
        public virtual ICollection<Tag> Tags { get; set; }       
    }

This is my model class:

public class MyPhotoModel
    {
        public IEnumerable<Photo> Photos { get; set; }
        public IEnumerable<Album> Album { get; set; }
        public ICollection<Tag> Tags { get; set; }

}

How can I read all three tables data in a table inside Index()  in controller page and show them in View page???

  MyPhotoModel model = new MyPhotoModel();
            model.Photos = db.Photos.Include("Album")
                                                   .Include("Tags");   

return View(model);

Hi hmsarab,

Thanks for your post.

hmsarab

How to show all data from three relationship forignkey tables in index action with my model

Please check Mike’s article:

#ASP.NET MVC, Entity Framework, One-to-Many and Many-to-Many INSERTS

http://www.mikesdotnetting.com/Article/109/ASP.NET-MVC-Entity-Framework-One-to-Many-and-Many-to-Many-INSERTS

Hope this can be helpful.

Best Regards,

Eileen

It is not my answer, I told that I need to read all tree tables data in a index() action

Just I need a single line as piece of code

Thanks

good post

[RESOLVED]CRUD in MVC 4

I write a app include CRUD in MVC 4 using Entity Framework. please everyone comments on my app about
performance, security,….

Thanks very much

http://youtu.be/X4VRBJP7ezQ

I recommend going through the asp.net articles and see whether you have followed the recommended practices. As always you can post your individual questions on this forum

I think that this is a way myself to see whether it has effective?

Thanks

[RESOLVED]Entity Framework Edit Model

Hello everybody

I just start work with Entity Framework and when I try to edit model I got a error "A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects
in the relationship."

The model what I try to edit is:

    public class CashboxCharge
    {
        [HiddenInput(DisplayValue = false)]
        public virtual Int32 ID { get; set; }

        //[DataType(DataType.Date)]
        //[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
        public virtual DateTime Date { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 OrganizationID { get; set; }

        [ForeignKey("OrganizationID")]
        public virtual Organization Organization { get; set; }

        public virtual IList<CashboxChargeItem> CashboxChargeItems { get; set; }
    }

and 

public class CashboxChargeItem
    {
        [HiddenInput(DisplayValue = false)]
        public virtual Int32 ID { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 ChargeID { get; set; }

        public virtual Charge Charge { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 ProgramID { get; set; }

        public virtual Program Program { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 SpecificityID { get; set; }

        public virtual Specificity Specificity { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 ArticleExpendureID { get; set; }

        public virtual ArticleExpendure ArticleExpendure { get; set; }

        public virtual float ExSumma { get; set; }
        public virtual float Summa { get; set; }

        [HiddenInput(DisplayValue = false)]
        public virtual Int32 CashboxChargeID { get; set; }

        [ForeignKey("CashboxChargeID")]
        public virtual CashboxCharge CashboxCharge { get; set; }
    }

For Edit I use code which was created by Add Controller

[HttpPost]
        public ActionResult Edit(CashboxCharge cashboxcharge, String param)
        {
            if (ModelState.IsValid)
            {
                cashboxcharge.CashboxChargeItems = JSON.Deserialize<IList<CashboxChargeItem>>(param);

                db.Entry(cashboxcharge).State = EntityState.Modified;
                db.SaveChanges();               
            }
            return this.Direct();
        }

Hi VSirchenko,

Thanks for your post.

VSirchenko

A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship."

Its seems that in some of its  collections that set the relationship with other entities exist some type of conflict. You could try to clear all the collections to see if the problem persists,  in this case you lost the foreign key assignment. But perhaps
could help you to locate the problem.

More information:

Entity Framework: A referential integrity constraint violation on many to many relationship

A referential integrity constraint violation occurred

Error:A referential integrity constraint violation occurred on db.SaveChanges() in .net?

If there’s anything else I can do for you regarding this matter,please feel free to let me know.

Best Regards,

Eileen