Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Order
- {
- [Key]
- public Guid Id { get; set; }
- [Required]
- public int Type { get; set; }
- [Required]
- public int Day { get; set; }
- public Guid? GroupId { get; set; }
- public Group Group { get; set; }
- public Guid? UserId{ get; set; }
- public User User { get; set; }
- }
- public class Author
- {
- [Key]
- [ForeignKey("User")]
- public Guid Id { get; set; }
- public virtual User User { get; set; }
- public virtual ICollection<Group> Groups { get; set; }
- public Author()
- {
- Groups = new List<Group>();
- }
- }
- public class User
- {
- public User()
- {
- Groups = new List<Group>();
- }
- [Key]
- [ForeignKey("Author")]
- public Guid Id { get; set; }
- [Required]
- public string Login { get; set; }
- [Required]
- public DateTime BirthDay { get; set; }
- [Required]
- public string FirsName { get; set; }
- [Required]
- public string SecondName { get; set; }
- [Required]
- public string Password { get; set; }
- [Required]
- public string AvatarPath { get; set; }
- [Required]
- public string ResponseQuestion { get; set; }
- [Required]
- public string SecretQuestion { get; set; }
- public virtual ICollection<Group> Groups { get; set; }
- public virtual Author Author { get; set; }
- public static implicit operator Author(User usr)
- {
- return new Author()
- {
- User = usr
- };
- }
- }
- public class Group
- {
- public Group()
- {
- this.Users = new List<User>();
- }
- [Key]
- public Guid Id { get; set; }
- public string Name { get; set; }
- public Guid? AuthorId{ get; set; }
- public virtual Author Author { get; set; }//Автор группы
- public virtual ICollection<User> Users { get; set; }
- public Group(string name, Author author)
- {
- this.Name = name;
- this.Author = author;
- }
- }
- public class StoreDB : DbContext
- {
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<User>()
- .HasOptional<Author>(a => a.Author)
- .WithRequired(a => a.User);
- }
- public DbSet<User> Users { get; set; }
- public DbSet<Group> Groups { get; set; }
- public DbSet<Order> Orders { get; set; }
- public DbSet<Author> Authors { get; set; }
- public User GetUser(string login)
- {
- return this.Users.FirstOrDefault((usr) => usr.Login == login);
- }
- public void AddUser(User usr)
- {
- this.Users.Add(usr);
- this.SaveChanges();
- }
- public void AddGroup(Group grp)
- {
- this.Groups.Add(grp);
- this.SaveChanges();
- }
- public bool IsContainUser(string login, string pass)
- {
- try
- {
- this.Users.First((u) => u.Login == login && u.Password == pass);
- return true;
- }
- catch
- {
- return false;
- }
- }
- public bool IsContainUser(string login)
- {
- try
- {
- this.Users.First((u) => u.Login == login);
- return true;
- }
- catch
- {
- return false;
- }
- }
- public bool ResponceOnQuestion(string login, string response)
- {
- try
- {
- this.Users.First(u => u.Login == login && u.ResponseQuestion == response);
- return true;
- }
- catch
- {
- return false;
- }
- }
- public void UpdatePassword(string login, string newPassword)
- {
- User updateUsr = this.Users.First(u => u.Login == login);
- updateUsr.Password = newPassword;
- this.Entry<User>(updateUsr).State = EntityState.Modified;
- this.SaveChanges();
- }
- }
- <add name="StoreDB" connectionString="data source=(localdb)v11.0;Initial Catalog=ChudoPechkaStore;Integrated Security=True;"
- providerName="System.Data.SqlClient"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement