Exemple #1
0
 internal static Utilizator GetUser(string email)
 {
     using (var dbContext = new DbModelContext())
     {
         var user = dbContext.Utilizator.FirstOrDefault(m => m.Email.Equals(email));
         return(user);
     }
 }
Exemple #2
0
 internal static Produs GetProductOnId(Guid productId)
 {
     using (var dbContext = new DbModelContext())
     {
         var prod = dbContext.Produs.Where(m => m.Id.Equals(productId)).FirstOrDefault();
         return(prod);
     }
 }
Exemple #3
0
        public static IEnumerable <Produs> SearchProductsInDatabase(string stringToSearch, string order)
        {
            var products = new List <Produs>();

            using (DbModelContext dbContext = new DbModelContext())
            {
                string searchIdiomCode = GetSearchCode(stringToSearch);

                int attempts = 0;
                while (true)
                {
                    Thread.Sleep(5 * 1000);
                    products = (from appear in dbContext.AparitieProdus
                                join search in dbContext.IstoricCautari on appear.Id_Cautare equals search.Id_Cautare
                                join product in dbContext.Produs on appear.Id_Produs equals product.Id
                                join retailer in dbContext.Vanzator on product.Id_Vanzator equals retailer.Id
                                where search.Cod == searchIdiomCode
                                select product).Include(p => p.Vanzator).ToList();
                    if (products.Count >= 1 || attempts > 30)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                    attempts++;
                }
            }
            switch (order)
            {
            case "price-asc":
            {
                products = products.OrderBy(m => m.Pret).ToList();
                break;
            }

            case "price-desc":
            {
                products = products.OrderByDescending(m => m.Pret).ToList();
                break;
            }

            case "retailer-asc":
            {
                products = products.OrderBy(m => m.Vanzator.Nume).ToList();
                break;
            }

            case "retailer-desc":
            {
                products = products.OrderByDescending(m => m.Vanzator.Nume).ToList();
                break;
            }

            default:
                break;
            }

            return(products);
        }
Exemple #4
0
        internal static List <Produs> GetFollowedProducts(Guid userId)
        {
            List <Produs> tempProds = new List <Produs>();

            using (var dbContext = new DbModelContext())
            {
                tempProds = (from products in dbContext.Produs
                             join followedProducts in dbContext.UrmarireProdus on products.Id equals followedProducts.Id_Produs
                             where followedProducts.Id_Utilizator == userId
                             where followedProducts.Invalid == false
                             select products).Include(p => p.Vanzator).ToList();
            }
            return(tempProds);
        }
Exemple #5
0
 private static void AddSearchPieceInDB(string piece)
 {
     using (DbModelContext dbContext = new DbModelContext())
     {
         IstoricCautari tempHistory = new IstoricCautari
         {
             Id_Cautare = StringToGUID(piece),
             Valoare    = piece.Trim(),
             Cod        = piece.Trim().GetHashCode().ToString()
         };
         dbContext.IstoricCautari.Add(tempHistory);
         dbContext.SaveChanges();
     }
 }
Exemple #6
0
        internal static void RemoveProductAlert(Guid userId, Guid productId)
        {
            try
            {
                using (var dbContext = new DbModelContext())
                {
                    var item = dbContext.UrmarireProdus.Where(m => m.Id_Produs.Equals(productId) && m.Id_Utilizator.Equals(userId)).FirstOrDefault();

                    item.Invalid = true;

                    dbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #7
0
 private static void InsertCompleteIdiomInDatabase(string stringToSearch, string searchIdiomCode)
 {
     using (DbModelContext dbContext = new DbModelContext())
     {
         try
         {
             IstoricCautari history = new IstoricCautari()
             {
                 Cod        = searchIdiomCode,
                 Valoare    = stringToSearch,
                 Id_Cautare = StringToGUID(stringToSearch)
             };
             dbContext.IstoricCautari.Add(history);
             dbContext.SaveChanges();
         }
         catch { }
     }
 }
Exemple #8
0
        internal static void AddUserToDb(UserModel user)
        {
            using (var dbContext = new DbModelContext())
            {
                var crypto = new SimpleCrypto.PBKDF2();

                var encPass = crypto.Compute(user.Parola);

                var tempUser = dbContext.Utilizator.Create();

                tempUser.Id              = Guid.NewGuid();
                tempUser.Numar_Telefon   = user.Numar_Telefon;
                tempUser.Nume_Utilizator = user.Nume_Utilizator;
                tempUser.Parola          = encPass;
                tempUser.Porecla         = user.Porecla;
                tempUser.Rol             = "0";
                tempUser.Email           = user.Email;
                tempUser.CheieParola     = crypto.Salt;

                dbContext.Utilizator.Add(tempUser);
                dbContext.SaveChanges();
            }
        }
Exemple #9
0
        internal static void AddProductAllert(Guid producId, Guid UserId, string price)
        {
            using (var dbContext = new DbModelContext())
            {
                try
                {
                    UrmarireProdus tempAlert = new UrmarireProdus();

                    tempAlert.Id                  = Guid.NewGuid();
                    tempAlert.Id_Produs           = producId;
                    tempAlert.Id_Utilizator       = UserId;
                    tempAlert.Limita_pret         = decimal.Parse(price);
                    tempAlert.Invalid             = false;
                    tempAlert.UtilizatorNotificat = false;
                    tempAlert.DataNotificarii     = DateTime.UtcNow;

                    dbContext.UrmarireProdus.Add(tempAlert);
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }