public User GetUserByUserName(string userName)
 {
     using (var context = new EFDbContext())
     {
         return (context.Users.Where(user => user.UserName == userName).First());
     }
 }
 public User GetUserByEmail(string email)
 {
     using (var context = new EFDbContext())
     {
         return (context.Users.Where(user => user.Email == email).First());
     }
 }
Exemple #3
0
        public UnitOfWork(ICarRepository carRepository, 
			IEquipmentRepository equipmentRepository,
			IManufacturerRepository manufacturerRepository,
			EFDbContext context)
        {
            CarRepository = carRepository;
            EquipmentRepository = equipmentRepository;
            ManufacturerRepository = manufacturerRepository;
            this.context = context;
        }
 public bool UserWasFound(User user)
 {
     User u = user;
     using (var context = new EFDbContext())
     {
         try
         {
             User dbEntry = context.Users.Where(usr => usr.UserName == user.UserName &&
                            usr.Password == user.Password && ((usr.Role == User.UserRole.Admin) || usr.Role == User.UserRole.Moderator)).First();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
Exemple #5
0
        public static void Initialize(EFDbContext context)
        {
            context.Database.EnsureCreated();


            if (context.RequestsStore.Any())
            {
                return;
            }

            var statuses = new List <Statuses>
            {
                new Statuses {
                    Name = "Открыта"
                },
                new Statuses {
                    Name = "Решена"
                },
                new Statuses {
                    Name = "Возврат"
                },
                new Statuses {
                    Name = "Закрыта"
                }
            };

            foreach (var item in statuses)
            {
                context.Statuses.Add(item);
            }
            context.SaveChanges();

            var requestStore = new List <RequestsStore>
            {
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-10),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-10),
                        Name       = "Что такое Lorem Ipsum?",
                        Content    = "<ul><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Vivamus suscipit ante at urna efficitur blandit.</li><li>Nam venenatis tellus id velit rhoncus, in finibus augue malesuada.</li></ul></p>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-9),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-9),
                        Name       = "Откуда появился Lorem Ipsum?",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-8),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-8),
                        Name       = "Почему он используется?",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-7),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-7),
                        Name       = "Где взять Lorem Ipsum?",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-6),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-6),
                        Name       = "Классический текст Lorem Ipsum, используемый с XVI века",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-5),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-5),
                        Name       = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras.",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-4),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-4),
                        Name       = "Lorem sit amet, adipiscing elit.",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-3),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-3),
                        Name       = "What is Lorem Ipsum?",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-2),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-2),
                        Name       = "Lorem ipsum dolor sit amet.",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
                new RequestsStore {
                    Date     = DateTime.Now.AddDays(-1),
                    StatusId = 1,
                    Comments = "Заявка создана",
                    Requests = new Requests
                    {
                        CreateDate = DateTime.Now.AddDays(-1),
                        Name       = "Lorem ipsum dolor sit amet, consectetur adipiscing.",
                        Content    = "<ul><li>Sed venenatis dui molestie libero elementum ultrices.</li><li>Vestibulum placerat risus eu odio accumsan viverra.</li><li>Nullam et sem ut purus egestas rutrum.</li><li>Praesent auctor tellus et mi rutrum, vel lacinia tortor luctus.</li><li>Nam at tortor euismod, gravida mi fringilla, laoreet magna.</li><li>Maecenas dictum ligula eu nibh mattis, eu pulvinar mi sodales.</li></ul>"
                    }
                },
            };

            foreach (var item in requestStore)
            {
                context.RequestsStore.Add(item);
            }

            context.SaveChanges();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            using (var db = new EFDbContext())
            //{
            //     var user = new User() { UserName = "******", Password = "******", Email = "*****@*****.**", Role = User.UserRole.Inactive, RegisterDate = DateTime.Now };
            //     var user1 = new User() { UserName = "******", Password = "******", Email = "*****@*****.**", Role = User.UserRole.Admin, RegisterDate = DateTime.Now };
            //     var user2 = new User() { UserName = "******", Password = "******", Email = "*****@*****.**", Role = User.UserRole.Moderator, RegisterDate = DateTime.Now };

            //    db.Users.Add(user);
            //    db.Users.Add(user1);
            //    db.Users.Add(user2);
                //var rest = new Restaraunt() { MaintenanceRate = 1, InteriorRate = 3, KitchenRate = 4, AddedDate = DateTime.Now, RestarauntType = Restaraunt.RestType.Cafe, Latitude = "1", Longitude = "2" };
                 //db.Restaraunts.Add(rest);
                //var image = new Image() { ImageMimeType = "123", ImageData = null };
                //var restLangs = new RestarauntLang() { Country = "rusTest0", Address = "rusTest0", Locality = "rusTest0", Name = "rusTest0", Region = "rusTest0", Review = "rusTest0" };
                //Language Test = db.Languages.Where(t => t.LanguageID == 1).First();
                //restLangs.LanguageID = Test.LanguageID;
                //restLangs.LanguageID = 6;
                //rest.RestLangs.Add(restLangs);
                //db.Restaraunts.Add(rest);
                //    var restLangs1 = new RestarauntLang() { Country = "engTest", Address = "engTest", Locality = "engTest", Name = "engTest", Region = "engTest", Review = "engTest" };
                //var language = new Language() { Name = "russian", Code = "rus" };
                //var language1 = new Language() { Name = "english", Code = "eng" };
                //var comment = new Comment() { Name = "bla bla", RestarauntID = 1, AddedDate = DateTime.Now, Review = "cool" };
                //var comment1 = new Comment() { Name = "gav gav", RestarauntID = 1, AddedDate = DateTime.Now, Review = "nice" };
                //  rest.RestLangs.Add(restLangs);
                // rest.RestLangs.Add(restLangs1);
                // language.RestLangs.Add(restLangs);
                //language1.RestLangs.Add(restLangs1);
               // db.Restaraunts.Add(rest);
                //db.Languages.Add(language);
                //db.Languages.Add(language1);

                try
                {
                    //var rl1 = db.RestarauntLangs.Where(rest => rest.Name == "Dolce la torre").First();
                    //var r1 = db.Restaraunts.Where(rest => rest.RestarauntID == rl1.RestarauntID).First();
                    //var img =
                    //foreach(var rest in db.Restaraunts)
                    //{
                    //    if ((rest.RestarauntID != 27) && (rest.RestarauntID != 33) && (rest.RestarauntID != 34))
                    //    {
                    //        db.Restaraunts.Remove(rest);
                    //    }
                    //}

                    //     EFUserRepository test = new EFUserRepository();
                    //  var lol = db.Restaraunts.Where(rest => rest.RestarauntID == 2).First();
                    // var lol2 = db.Restaraunts.Where(rest => rest.RestarauntID == 1).First();
                    //   var lol1 = db.Restaraunts.Where(rest => rest.RestarauntID == 20).First();
                    //db.Restaraunts.Remove(lol);
                    // db.Restaraunts.Remove(lol1);
                    //db.Restaraunts.Remove(lol2);

                    //  var lang = db.Languages.Where(l => l.LanguageID == 1).First();
                    // db.Languages.Remove(lang);
                    //  User u = db.Users.Where(usr => usr.UserID == 4).First();
                    //u.Role = User.UserRole.Moderator;
                    //test.SaveUser(u);
                    //foreach (var obj in db.Restaraunts)
                    //{
                    //    db.Restaraunts.Remove(obj);
                    //}
                    //foreach (var obj in db.Images)
                    //{
                    //    db.Images.Remove(obj);
                    //}
                    //foreach (var obj in db.RestarauntLangs)
                    //{
                    //    db.RestarauntLangs.Remove(obj);
                    //}
                    // db.SaveChanges();
                    //User usr = db.Users.Where(user => user.Email == "*****@*****.**").First();
                    //usr.Role = User.UserRole.Moderator;
                    // foreach(Image img in db.Images)
                    /*  {
                          db.Images.Remove(img);
                      }*/
                    // Console.WriteLine(DateTime.Now.ToFileTime());
                    //Image tmp = db.Images.Where(img => img.ImageID == 5).First();
                    //Image tmp1 = db.Images.Where(img => img.ImageID == 6).First();
                    // db.SaveChanges();
                    //   User user = context.Users.Where(usr => usr.Email == "*****@*****.**").First();
                    // Console.WriteLine(user.UserName + " " + user.Password + " " + user.Role);

                    // User user = context.Users.Find(1);
                    // user.Role = User.UserRole.Moderator;
                    //context.SaveChanges();
                    //   User dbEntry = db.Users.Where(usr => usr.UserName == "admin").First();
                    // Console.WriteLine(dbEntry.UserName + dbEntry.Password + dbEntry.Role);
                    // foreach(User usr in db.Users)
                    //{
                    //    Console.WriteLine(usr.UserName + usr.Password + usr.Role);
                    //}
                    //foreach (var u in db.Users)
                    // {
                    // Console.WriteLine("Name: {0} Password: {1} Email: {2} Role: {3}", u.UserName, u.Password, u.Email, u.Role);
                    //}
                }
                catch
                {
                    Console.WriteLine("SHIIIT");
                }
        }
 public EFRequestsRepository(EFDbContext context)
 {
     this.context = context;
 }
Exemple #8
0
        public IEnumerable <User> GetAllUsers()
        {
            var context = new EFDbContext();

            return(context.Users.ToList());
        }
 public EFCartRepository(EFDbContext context)
 {
     _context = context;
 }
 public EFProductReposity(EFDbContext context)
 {
     _context = context;
 }