ASPNET Core How to Update Multiple Records Using Chekboxes - asp.net

I have a simple ASPNET core Razor WEB App.
In this I have a the following Model classes
public class Student
{
public int ID { get; set; }
public string RegID { get; set; }
public string Name { get; set; }
public int? SectionID { get; set; }
public Section Section { get; set; }
}
public class Section
{
public int ID { get; set; }
public string Name { get; set; }
}
What I want to Create is a razor page where I can select a Section, and Select multiple students and Submit to Update All the selected students with the new selected sections.
Any kind of Help will be appreciated, Even ones with MVC solution.
Regards

Related

ASP.NET MVC Entity Frame Work : Code First Approach

I am working ASP.NET MVC using Entity frame work code first approach. I am facing an issue ,the issue is as i have dropped two tables by using Package Manager Console.
Now i am trying to add the tables, the tables are not getting added using Package Manager Console.
Getting Error Cannot find the object "dbo.Movies" because it does not exist or you do not have permissions.
Even in Indentity.cs Model [Movies] is mentioned.
public DbSet Movies { get; set; }
Below are the Model.
public class Movie
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime ReleaseDate { get; set; }
public Genre Genres { get; set; }
public byte GenreId { get; set; }
public DateTime DateAdded { get; set; }
public int NumberOfStocks { get; set; }
}
public class Genre
{
public byte Id { get; set; }
public string Type { get; set; }
}
How to the add the new table in existing Entity frame work using Code first approach.

MVC with EF: Scaffold DropDownList

What I'm trying to do
Automatically scaffold my Controller and Views based on my Model.
The Problem
My DropDownLists (a SelectedItemList) doesn't appear, instead I get a NumericUpDown element.
The Relation
A 'Bekroning' can have one 'Bekroner'.
A 'Bekroner' can 'bekroon' many 'Bekroningen'.
The Model
public class Bekroning
{
public int ID { get; set; }
[Required]
public int Omschrijving{ get; set; }
[Required]
public int Bekroner_ID { get; set; }
}
public class Bekroner
{
public int ID { get; set; }
[Required]
public string Naam { get; set; }
}
Similar Questions
MVC 5 Code First scaffolding with simple relationship
MvcScaffolding one-many relationship
But I can't get my head around it. Thanks in advance.

ASP.NET MVC 6 Update Multiple Tables from One View

I’m coming from an intermediate C++ background (and to a lesser extent, C#) and wanted to try to build a project in Asp.net MVC 6 with EF 7 – not realizing how completely different it is from simple C# forms. I’ve stumbled through and researched a lot but since I’m a total noob I’m stumped at this point.
I have the following models:
public class Shift
{
public int ShiftId { get; set; }
//other properties
public virtual ICollection<ShiftActivity> ShiftActivity { get; set;}
}
public class ShiftActivity
{
public int ShiftActivityID { get; set; }
public DateTime StartTime { get; set; }
public int ShiftID { get; set; }
public int ActivityID { get; set; }
public int LocationID { get; set; }
public virtual Shift Shift { get; set; }
public virtual Activity Activity { get; set; }
public virtual Location Location { get; set; }
}
public class Activity
{
public int ActivityID { get; set; }
public string ActivityName { get; set; }
public virtual ICollection<ShiftActivity> ShiftActivity { get; set; }
}
public class Location
{
public int LocationID { get; set; }
public string LocationName { get; set; }
public string LocationAddress { get; set; }
public int locationZip { get; set; }
public virtual ICollection<ShiftActivity> ShiftActivity { get; set; }
}
I would like to create a shift and be able to input all the required fields all from one view. For instance, when I create the shift, I need to pick the type of location and activity to add to the ShiftActivity table which is then updated. Eventually I would like to be able to dynamically add additional activities (I’m assuming I’ll need javascript for that), but that’s another issue. I know I need a viewmodel to access all the tables, but I’m unclear as to how the viewmodel should be structured correctly.
Also, can the ShiftController update the ShiftActivity table directly or do I need to transfer the data somehow to the ShiftAcitivityController when the form is submitted? Either way, can someone point me to an example? Thank you… Any help is greatly appreciated.

ASP.NET Identity for WebForms - getting started with extending User attributes

I'm working on my first ASP.NET WebForms project using Identity. I ticked the box when creating the project and the basics all seem to be working OK. Now I want to extend the Register form and the AspNetUsers table with new attributes (e.g. Users (actual) Name). I'd also like to expose the existing PhoneNumber attribute.
I did some research but couldn't find any non-MVC info on this scenario. Is the expectation that I just hack away at the template code to achieve this?
I'm happy to do so, just wondering if I am missing something...
As you say you are using an ASP.NET Web From with default files and folders.
Please open the IdentityMode.cs in Models folder and find ApplicationUser class.
In this class you can add user attributes as properties, see example :
01: add profile information in users table:
public class ApplicationUser : IdentityUser
{
[Required]
public string UserFullName { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string PhoneNumber { get; set; }
[Required]
public string Address { get; set; }
public DateTime RegisteredDate { get; set; }
public string Info { get; set; }
}
02 :
you can add profile information in different table :
public class ApplicationUser : IdentityUser
{
public virtual UserInfo UserInfo { get; set; }
}
public class UserInfo
{
[Required]
public string UserFullName { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string PhoneNumber { get; set; }
[Required]
public string Address { get; set; }
public DateTime RegisteredDate { get; set; }
public string Info { get; set; }
}

Entity Framework 5 Code First - Non-Nullable Foriegn Key Fields

I am new to Entity Framework and about to embark on a new ASP.NET MVC project using EF5 Code First.
I noticed whilst trying out EF that the Foreign Key fields that are automatically generated for me in my database allow NULL's and I wonder how I configure things in code so as it doesn't allow nulls for these fields?
Example (edited for brevity):
public class Shop
{
int Id { get; set; }
string Name { get; set;
// Navigation Property.
Certificate Certificate { get; set; } // ******
}
public class Certificate
{
int Id { get; set; }
string Descrip { get; set; }
}
The Navigation Property that I have highlighted automatically generates a field in the Shop table in the DB, called Certificate_Id, but it allows NULL and I'd like to specify that it should not allow NULL's.
How can I do this using the Fluent API?
Try like this:
public class TempContext : DbContext
{
public DbSet<Shop> Shops { get; set; }
public DbSet<Certificate> Certificates { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Shop>().HasRequired(x => x.Certificate);
}
}
You could use the Required attribute to mark a property as required.
MSDN
Here is your example:
public class Shop
{
int Id { get; set; }
string Name { get; set;
[Required]
Certificate Certificate { get; set; }
}
Here is an explanation of the different annotations.
Try this:
public class Shop
{
int Id { get; set; }
string Name { get; set; }
[Required]
int CertId { get; set; }
// Navigation Property.
[ForeignKey("CertId")]
Certificate Certificate { get; set; } // ******
}
public class Certificate
{
int Id { get; set; }
string Descrip { get; set; }
}

Resources