Пример #1
0
 public long FindUserId(string userName)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         long id = asp.Users.Where(u => u.UserName == userName).Select(u => u.UserID).SingleOrDefault();
         return(id);
     }
 }
Пример #2
0
 public void AddProduct(Product p)
 {
     using (var db = new AspProjectEntities())
     {
         db.Products.Add(p);
         db.SaveChanges();
     }
 }
Пример #3
0
 public bool FindIfUserExist(string userName)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         foreach (var user in asp.Users)
         {
             if (user.UserName == userName)
             {
                 return(false);
             }
         }
         return(true);
     }
 }
 public void ChangeProductStateToBoughtGuest(long id)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         var p = asp.Products.Where(prod => prod.State == (int)state.cart && prod.ProductID == id).FirstOrDefault();
         if (p != null)
         {
             p.OwnerID          = null;
             p.State            = (int)state.bought;
             asp.Entry(p).State = EntityState.Modified;
             asp.SaveChanges();
         }
     }
 }
 public void ChangeProductStateToAvailable()
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         Product p = asp.Products.Where(prod => prod.State == (int)state.cart).SingleOrDefault();
         if (p != null)
         {
             p.State            = (int)state.upload;
             p.UserID           = null;
             asp.Entry(p).State = EntityState.Modified;
             asp.SaveChanges();
         }
     }
 }
Пример #6
0
 public User FindUser(string userName, string password)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         foreach (User user in asp.Users)
         {
             if (user.UserName == userName && user.Password == password)
             {
                 return(user);
             }
         }
         return(null);
     }
 }
 public void ChangeProductStateToCart(long ID, long uID)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         Product p = asp.Products.Where(prod => prod.ProductID == ID && prod.State == (int)state.upload).FirstOrDefault();
         if (p != null)
         {
             p.DateAddedToCart  = DateTime.Now;
             p.UserID           = uID;
             p.State            = (int)state.cart;
             asp.Entry(p).State = EntityState.Modified;
             asp.SaveChanges();
         }
     }
 }
        public void ChangeProductStateAddedToCart()
        {
            var date = DateTime.Now.AddMinutes(-20);

            using (AspProjectEntities asp = new AspProjectEntities())
            {
                var prod = asp.Products.Where(p => p.State == (int)state.cart && date > p.DateAddedToCart).ToList();
                foreach (var p in prod)
                {
                    p.UserID           = null;
                    p.State            = (int)state.upload;
                    asp.Entry(p).State = EntityState.Modified;
                    asp.SaveChanges();
                }
            }
        }
Пример #9
0
 public UsersModel FindUserModelByUserName(string uName)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         UsersModel user = (from u in asp.Users
                            where u.UserName == uName
                            select new UsersModel
         {
             userName = u.UserName,
             password = u.Password,
             birthDate = u.BirthDate,
             email = u.Email,
             firstName = u.FirstName,
             lastName = u.LastName
         }).SingleOrDefault();
         return(user);
     }
 }
Пример #10
0
 public UsersModel FindUserModelByID(long ID)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         var u = (from use in asp.Users
                  where use.UserID == ID
                  select new UsersModel
         {
             firstName = use.FirstName,
             lastName = use.LastName,
             birthDate = use.BirthDate,
             email = use.Email,
             password = use.Password,
             userName = use.UserName
         }).SingleOrDefault();
         return(u);
     }
 }
Пример #11
0
        public void AddUser(UsersModel user)
        {
            User newUser = new User()
            {
                FirstName = user.firstName,
                LastName  = user.lastName,
                BirthDate = user.birthDate,
                Email     = user.email,
                UserName  = user.userName,
                Password  = user.password
            };

            using (var db = new AspProjectEntities())
            {
                db.Users.Add(newUser);
                db.SaveChanges();
            }
        }
 public void ChangeProductStateToBoughtUser(long uID)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         var p = asp.Products.Where(prod => prod.State == (int)state.cart &&
                                    prod.UserID == uID).ToList();
         foreach (var item in p)
         {
             if (item != null)
             {
                 item.State            = (int)state.bought;
                 item.OwnerID          = item.UserID;
                 item.UserID           = null;
                 asp.Entry(item).State = EntityState.Modified;
                 asp.SaveChanges();
             }
         }
     }
 }
Пример #13
0
 public List <ProductsModel> ProductsInCart(long uID)
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         var products = (from p in asp.Products
                         where p.State == (int)state.cart && p.UserID == uID
                         select new ProductsModel
         {
             title = p.Title,
             price = p.Price,
             shortDescription = p.ShortDescription,
             longDescription = p.LongDescription,
             image1 = p.Picture1,
             image2 = p.Picture2,
             image3 = p.Picture3,
             date = p.Date,
             status = (state)p.State,
             ID = p.ProductID,
             userID = (long)p.UserID
         }).ToList();
         return(products);
     }
 }
Пример #14
0
 public IEnumerable <ProductsModel> SortByDate()
 {
     using (AspProjectEntities asp = new AspProjectEntities())
     {
         var products = (from p in asp.Products
                         orderby p.Date ascending
                         where p.State == (int)state.upload
                         select new ProductsModel
         {
             title = p.Title,
             price = (long)p.Price,
             shortDescription = p.ShortDescription,
             longDescription = p.LongDescription,
             image1 = p.Picture1,
             image2 = p.Picture2,
             image3 = p.Picture3,
             date = p.Date,
             status = (state)p.State,
             ID = p.ProductID
         }).ToList();
         return(products);
     }
 }
        public ProductsModel FindProductModelByID(long ID)
        {
            FindUserRepository find = new FindUserRepository();

            using (AspProjectEntities asp = new AspProjectEntities())
            {
                var product = (from p in asp.Products
                               where p.ProductID == ID
                               select new ProductsModel
                {
                    title = p.Title,
                    price = p.Price,
                    shortDescription = p.ShortDescription,
                    longDescription = p.LongDescription,
                    date = p.Date,
                    ownerID = (long)p.OwnerID,
                    ID = p.ProductID,
                    image1 = p.Picture1,
                    image2 = p.Picture2,
                    image3 = p.Picture3
                }).SingleOrDefault();
                return(product);
            }
        }