Beispiel #1
0
 public static WebResult <List <SearchDetailsForUser> > SearchByStatus(string passwordUser, EStatus status)
 {
     using (ProjectEntities db = new ProjectEntities())
     {
         User CurrentUser = db.Users.FirstOrDefault(f => f.passwordUser == passwordUser);
         List <SearchDetailsForUser> searchesForUser = new List <SearchDetailsForUser>();
         var searches = SearchCast.GetSearchesDTO(db.Searches.ToList());
         foreach (var search in searches)
         {
             if (search.codeUser == CurrentUser.codeUser && search.status == status)
             {
                 searchesForUser.Add(new SearchDetailsForUser()
                 {
                     CodeSearch   = search.codeSearch,
                     NameProduct  = search.nameProduct,
                     nameCategory = db.Categories.First(f => f.codeCategory == search.codeCategory).nameCategory,
                     Status       = search.status,
                     nameShop     = search.codeShop == null ? "" : db.Shops.First(f => f.codeShop == search.codeShop).nameShop
                 });
             }
         }
         searchesForUser.Reverse();
         return(new WebResult <List <SearchDetailsForUser> >
         {
             Message = "חיפושי המשתמש נשלחו בהצלחה",
             Value = searchesForUser,
             Status = true
         });
     }
 }
Beispiel #2
0
        //Returns history of the searches, even thouse the user found
        public static WebResult <List <SearchDetailsForUser> > GetHistory(string passwordUser)
        {
            using (ProjectEntities db = new ProjectEntities())
            {
                string pass        = passwordUser;
                User   CurrentUser = db.Users.FirstOrDefault(f => f.passwordUser == pass);
                if (CurrentUser == null)
                {
                    return(new WebResult <List <SearchDetailsForUser> >
                    {
                        Message = "the user cant find!",
                        Value = null,
                        Status = false
                    });
                }
                List <SearchDetailsForUser> searchesForUser = new List <SearchDetailsForUser>();
                var searches = SearchCast.GetSearchesDTO(db.Searches.ToList());
                foreach (var search in searches)
                {
                    if (search.codeUser == CurrentUser.codeUser && search.status != EStatus.Deleted)
                    {
                        searchesForUser.Add(new SearchDetailsForUser()
                        {
                            CodeSearch     = search.codeSearch,
                            NameProduct    = search.nameProduct,
                            nameCategory   = db.Categories.First(f => f.codeCategory == search.codeCategory).nameCategory,
                            Status         = search.status,
                            dateStart      = search.dateStart,
                            dateEnd        = search.dateEnd,
                            codeShop       = search.codeShop,
                            nameShop       = search.codeShop == null ? "" : db.Shops.First(f => f.codeShop == search.codeShop).nameShop,
                            IsFavoriteShop = search.codeShop == null ? null : db.Shops.First(f => f.codeShop == search.codeShop).isFavorite
                        });
                    }
                }

                string queryString = @"
                        UPDATE Shops
                        SET 
                        Shops.isFavorite = 1
                        FROM Shops
                        INNER JOIN Searches
                        ON Shops.codeShop = Searches.codeShop
                        ";
                int    effected    = db.Database.ExecuteSqlCommand(queryString);

                searchesForUser.Reverse();
                return(new WebResult <List <SearchDetailsForUser> >
                {
                    Message = "חיפושי המשתמש נשלחו בהצלחה",
                    Value = searchesForUser,
                    Status = true
                });
            }
        }
Beispiel #3
0
 public static WebResult <List <SearchDTO> > UpdateavoritesShops()
 {
     using (ProjectEntities db = new ProjectEntities())
     {
         foreach (var s in db.Searches)
         {
         }
         db.SaveChanges();
         return(new WebResult <List <SearchDTO> >
         {
             Message = "רשימת חנויות מועדפות עודכנה בהצלחה",
             Status = true,
             Value = SearchCast.GetSearchesDTO(db.Searches.ToList())
         });
     }
 }
Beispiel #4
0
 public static WebResult <List <SearchDTO> > UpdateAllSearchStatus()
 {
     using (ProjectEntities db = new ProjectEntities())
     {
         foreach (var s in db.Searches)
         {
             UpdateSearchStatus(s.codeSearch, CheckStatus(SearchCast.GetSearchDTO(s)), null);
         }
         db.SaveChanges();
         return(new WebResult <List <SearchDTO> >
         {
             Message = "רשימת מטלות עודכנה בהצלחה",
             Status = true,
             Value = SearchCast.GetSearchesDTO(db.Searches.ToList())
         });
     }
 }
Beispiel #5
0
 //פונקציה שמחזירה למשתמש את כל החיפושים שנמצאו
 public static WebResult <List <SearchDTO> > getfoundSearchesByUserId(int userId)
 {
     if ((HttpContext.Current.Session["User"] as User).codeUser != userId)
     {
         return new WebResult <List <SearchDTO> >
                {
                    Message = "שגיאת אבטחה, משתמש לא תואם",
                    Value   = null,
                    Status  = false
                }
     }
     ;
     return(new WebResult <List <SearchDTO> >
     {
         Message = "חיפושי המשתמש שנמצאו נשלחו בהצלחה",
         Value = SearchCast.GetSearchesDTO(db.Searches.Where(w => w.codeUser == userId && w.status == 1).ToList()),
         Status = true
     });
 }
Beispiel #6
0
        //פונקציה שמחזירה למשתמש את כל החיפושים שלו כולל אלו שמצא
        //מה עדיף? לקבל אובייקט של משתמש או רק המזהה, כי אם נקבל אובייקט נוכל מיד לגשת לרשימה של החיפושים???????????
        public static WebResult <List <SearchDTO> > GetSearchesByUserId()
        {
            if ((HttpContext.Current.Session["User"] as User) == null)
            {
                return new WebResult <List <SearchDTO> >
                       {
                           Message = "שגיאת אבטחה, משתמש לא תואם",
                           Value   = null,
                           Status  = false
                       }
            }
            ;
            User          CurrentUser = HttpContext.Current.Session["User"] as User;
            List <Search> searches    = db.Searches.Where(w => w.codeUser == CurrentUser.codeUser && w.status != 2).ToList();

            return(new WebResult <List <SearchDTO> >
            {
                Message = "חיפושי המשתמש נשלחו בהצלחה",
                Value = SearchCast.GetSearchesDTO(searches),
                Status = true
            });
        }