Ejemplo n.º 1
0
        public static void AddUserSearchHistory(int idPlace, string userId, DateTime date)
        {
            UserSearchHistory ush = new UserSearchHistory {
                IdPlace = idPlace, IdUser = userId, SearchDate = date
            };

            using (var db = new EntitiesContext())
            {
                db.UserSearchHistories.Add(ush);
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public void TestUserSearchHistory()
        {
            var sut = new UserSearchHistory()
            {
                HistoryId    = 47,
                SearchString = "Anis",
                UserId       = 4,
                User         = new User()
                {
                    UserId = 4, Lastname = "Medini"
                },
                SearchDate = DateTime.Today
            };

            var expected = DateTime.Today;
            var result   = sut.SearchDate;

            Assert.Equal(expected, result);
        }
Ejemplo n.º 3
0
 public SearchResponse DoSearch(int userId, string key)
 {
     try
     {
         UserSearchHistory userSearchHistory = new UserSearchHistory();
         userSearchHistory.UserId  = userId;
         userSearchHistory.Keyword = key;
         var                BaseCourses    = db.Courses.Include("Category").Include("Center").Where(c => (c.isStarted == true) && (c.Name.Contains(key) || c.Center.Name.Contains(key) || c.Category.Name.Contains(key))).ToList();
         var                BaseCenters    = db.Centers.Include("Category").Include("Courses").Where(c => c.IsConfirmed).ToList();
         var                BaseCategories = db.Categories.Include("Courses").Include("Centers").ToList();
         List <Course>      BigCourses     = new List <Course>();
         List <Center>      BigCenters     = new List <Center>();
         List <SmallCenter> SmallCenter    = new List <SmallCenter>();
         List <SmallCourse> SmallCourse    = new List <SmallCourse>();
         //Remove Duplicate
         BigCourses = BaseCourses;
         foreach (var basecenter in BaseCenters)
         {
             if (basecenter.Name.Contains(key))
             {
                 BigCenters.Add(basecenter);
             }
             var cats = db.TrainningCenterCategories.Include("Category").Where(c => c.CentersId == basecenter.Id).ToList();
             foreach (var item in cats)
             {
                 if (item.Category.Name.Contains(key))
                 {
                     BigCenters.Add(basecenter);
                 }
             }
         }
         foreach (var bigCenter in BigCenters)
         {
             SmallCenter SM = new SmallCenter
             {
                 CenterName = bigCenter.Name,
                 CenterRate = (int)new Utilities().GetCenterRate(bigCenter.Id),
                 Id         = bigCenter.Id,
                 Email      = bigCenter.Email,
                 Location   = bigCenter.LocationLat + ";" + bigCenter.LocationLong,
                 Logo       = Convert.ToBase64String(bigCenter.Logo),
                 Phones     = new List <string> {
                     bigCenter.Phone1, bigCenter.Phone2, bigCenter.Phone3
                 }
             };
             SmallCenter.Add(SM);
         }
         foreach (var bigCourse in BigCourses)
         {
             var         cname = db.Centers.SingleOrDefault(c => c.Id == bigCourse.CenterId).Name;
             var         loves = db.CoursLoves.Where(co => co.CourseId == bigCourse.Id).ToList().Count;
             SmallCourse SC    = new SmallCourse
             {
                 id         = bigCourse.Id,
                 Name       = bigCourse.Name,
                 Hours      = bigCourse.Hours,
                 BeginDate  = bigCourse.BeginDate.ToShortDateString(),
                 EndDate    = bigCourse.EndDate.ToShortDateString(),
                 CourseLogo = Convert.ToBase64String(bigCourse.Logo),
                 Rate       = new Utilities().GetCenterRate(bigCourse.CenterId),
                 CenterName = cname,
                 Price      = bigCourse.Price,
                 Instructor = bigCourse.Instructor,
                 Loves      = loves,
                 CenterId   = bigCourse.CenterId
             };
             SmallCourse.Add(SC);
             var         BC = db.Centers.SingleOrDefault(cen => cen.Id == SC.CenterId);
             SmallCenter SM = new SmallCenter
             {
                 CenterName = BC.Name,
                 CenterRate = (int)new Utilities().GetCenterRate(BC.Id),
                 Id         = BC.Id,
                 Email      = BC.Email,
                 Location   = BC.LocationLat + ";" + BC.LocationLong,
                 Logo       = Convert.ToBase64String(BC.Logo),
                 Phones     = new List <string> {
                     BC.Phone1, BC.Phone2, BC.Phone3
                 }
             };
             foreach (var Small in SmallCenter)
             {
                 if (SM.Id != Small.Id)
                 {
                     SmallCenter.Add(SM);
                 }
             }
         }
         SmallCenter = SmallCenter.Distinct().ToList();
         var result = new SearchResponse
         {
             smallCenters = SmallCenter,
             smallCourses = SmallCourse,
             Message      = Utilities.GetErrorMessages("200")
         };
         userSearchHistory.Result = System.Web.Helpers.Json.Encode(result);
         db.UserSearchHistories.Add(userSearchHistory);
         return(result);
     }
     catch (Exception ex)
     {
         return(new SearchResponse
         {
             Message = Utilities.GetErrorMessages("500")
         });
     }
 }