Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CompanyAdmin
- {
- public string Id { get; set; }
- [Required(AllowEmptyStrings = false)]
- [Display(Name = "Company Name")]
- public string CompanyName { get; set; }
- public virtual List<Certificate> Certificates { get; set; }
- public class Certificate
- {
- [Key]
- [Display(Name = "Certificate No.")]
- public string CertNo { get; set; }
- [Display(Name = "Company")]
- public IEnumerable<SelectListItem> Companies { get; set; }
- [Required]
- public string Company { get; set; }
- [Display(Name = "User")]
- public IEnumerable<SelectListItem> UserList { get; set; }
- [Required]
- public string User { get; set; }
- public string UploadedBy { get; set; }
- [Display(Name = "Description")]
- public string CertDescription { get; set; }
- [Display(Name = "File Location")]
- public string CertFileLocation { get; set; }
- [Display(Name = "Last Modified")]
- public DateTime LastModifiedDate { get; set; }
- }
- public class CertificateViewModel
- {
- [Display(Name = "Certificate No.")]
- public string CertNo { get; set; }
- public string User { get; set; }
- [Display(Name = "User")]
- public string UserName { get; set; }
- public string Company { get; set; }
- [Display(Name = "Company")]
- public string CompanyName { get; set; }
- [Display(Name = "Description")]
- public string CertDescription { get; set; }
- [Display(Name = "Last Modified")]
- public DateTime LastModifiedDate { get; set; }
- }
- public ActionResult Index()
- {
- if (User.IsInRole("Admin"))
- {
- IEnumerable<CertificateViewModel> model = null;
- model = (from c in db.CertificateDB
- join u in db.Users on c.User equals u.Id
- join d in db.CompanyDB on c.Company equals d.Id
- select new CertificateViewModel
- {
- CertNo = c.CertNo,
- UserName = u.UserName,
- CompanyName = d.CompanyName,
- CertDescription = c.CertDescription,
- LastModifiedDate = c.LastModifiedDate
- }
- );
- return View(model);
- }
- else
- {
- return RedirectToAction("Index", "Home");
- }
- }
- @model IEnumerable<IdentitySample.Models.CertificateViewModel>
- <table class="table">
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.CertNo)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Company)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.User)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.CertDescription)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.LastModifiedDate)
- </th>
- <th></th>
- </tr>
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.CertNo)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Company)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.User)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.CertDescription)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.LastModifiedDate)
- </td>
- <td>
- @Html.ActionLink("Edit", "Edit", new { id = item.CertNo }) |
- @Html.ActionLink("Details", "Details", new { id = item.CertNo }) |
- @Html.ActionLink("Delete", "Delete", new { id = item.CertNo })
- </td>
- </tr>
- }
- </table>
- public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
- {
- public ApplicationDbContext()
- : base("DefaultConnection", throwIfV1Schema: false)
- {
- }
- static ApplicationDbContext()
- {
- // Set the database intializer which is run once during application start
- // This seeds the database with admin user credentials and admin role
- Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
- }
- public override int SaveChanges()
- {
- try
- {
- return base.SaveChanges();
- }
- catch (DbEntityValidationException ex)
- {
- string errorMessages = string.Join("; ", ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.PropertyName + ": " + x.ErrorMessage));
- throw new DbEntityValidationException(errorMessages);
- }
- }
- public DbSet<CompanyAdmin> CompanyDB { get; set; }
- public DbSet<Certificate> CertificateDB { get; set; }
- public static ApplicationDbContext Create()
- {
- return new ApplicationDbContext();
- }
- }
Add Comment
Please, Sign In to add comment