Advertisement
Mihai_Preda

Untitled

Dec 8th, 2020
2,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.92 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Data.Entity;
  3. using System.Security.Claims;
  4. using System.Threading.Tasks;
  5. using System.Web.Mvc;
  6. using DigitalSchoolGroupsPlatform.Models;
  7. using Microsoft.AspNet.Identity;
  8. using Microsoft.AspNet.Identity.EntityFramework;
  9. using System.ComponentModel.DataAnnotations.Schema;
  10. using System.ComponentModel.DataAnnotations;
  11.  
  12. namespace DigitalSchoolGroups.Models
  13. {
  14.     // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
  15.     public class ApplicationUser : IdentityUser
  16.     {
  17.         public IEnumerable<SelectListItem> AllRoles { get; set; }
  18.  
  19.         public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
  20.         {
  21.             // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
  22.             var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
  23.             // Add custom user claims here
  24.             return userIdentity;
  25.         }
  26.  
  27.         public virtual ICollection<Group> Groups { get; set; }
  28.         //public virtual ICollection<Group> GroupsRequests { get; set; }
  29.  
  30.         public bool IsInGroup(Group group)
  31.         {
  32.             if (group.UserId == Id)
  33.                 return true;
  34.             foreach (DigitalSchoolGroupsPlatform.Models.Group gr in Groups)
  35.             {
  36.                 if (gr.Id == group.Id)
  37.                     return true;
  38.             }
  39.             return false;
  40.         }
  41.  
  42.         public bool RequestedToJoin(Group group)
  43.         {
  44.             return false;
  45.           /*  foreach (DigitalSchoolGroupsPlatform.Models.Group gr in GroupsRequests)
  46.             {
  47.                 if (gr.Id == group.Id)
  48.                     return true;
  49.             }
  50.             return false;*/
  51.         }
  52.  
  53.         public void DeleteJoinRequest(Group group)
  54.         {
  55.             /*group.Requests.Remove(this);
  56.             GroupsRequests.Remove(group);*/
  57.         }
  58.     }
  59.  
  60.     public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
  61.     {
  62.  
  63.         public ApplicationDbContext()
  64.             : base("DefaultConnection", throwIfV1Schema: false)
  65.         {
  66.             Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext,
  67.                 DigitalSchoolGroups.Migrations.Configuration>("DefaultConnection"));
  68.  
  69.         }
  70.  
  71.         public DbSet<Group> Groups { get; set; }
  72.         public DbSet<Category> Categories { get; set; }
  73.         public DbSet<Message> Messages { get; set; }
  74.  
  75.         public static ApplicationDbContext Create()
  76.         {
  77.             return new ApplicationDbContext();
  78.         }
  79.  
  80.         protected override void OnModelCreating(DbModelBuilder modelBuilder)
  81.         {
  82.             base.OnModelCreating(modelBuilder);
  83.         }
  84.     }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement