Esempio n. 1
0
 public CenterResponse GetCenterProfile(int userId, int centerId)
 {
     try
     {
         var center = db.Centers.SingleOrDefault(cen => cen.Id == centerId);
         if (center != null)
         {
             bool        userRated   = db.CenterRates.Any(r => r.UserId == userId && r.CenterId == centerId);
             SmallCenter smallCenter = new SmallCenter
             {
                 CenterName = center.Name,
                 CenterRate = userRated ? 0 : (int)new Utilities().GetCenterRate(center.Id),
                 Id         = center.Id,
                 Email      = center.Email,
                 Location   = center.LocationLat + "*" + center.LocationLong,
                 Logo       = Convert.ToBase64String(center.Logo),
                 Phones     = new List <string> {
                     center.Phone1, center.Phone2, center.Phone3
                 }
             };
             return(new CenterResponse
             {
                 center = smallCenter,
                 Message = Utilities.GetErrorMessages("200")
             });
         }
         else
         {
             return(new CenterResponse
             {
                 Message = Utilities.GetErrorMessages("402"),
             });
         }
     }
     catch (Exception ex)
     {
         return(new CenterResponse
         {
             Message = Utilities.GetErrorMessages("500"),
         });
     }
 }
Esempio n. 2
0
 public CentersResponse GetCenters(int count, int skip)
 {
     try
     {
         var bigCenters = db.Centers.Where(c => c.IsConfirmed).ToList();
         List <SmallCenter> SmallCenters = new List <SmallCenter>();
         foreach (var center in bigCenters)
         {
             SmallCenter smallCenter = new SmallCenter
             {
                 CenterName = center.Name,
                 CenterRate = (int)new Utilities().GetCenterRate(center.Id),
                 Id         = center.Id,
                 Email      = center.Email,
                 Location   = center.LocationLat + ";" + center.LocationLong,
                 Logo       = Convert.ToBase64String(center.Logo),
                 Phones     = new List <string> {
                     center.Phone1, center.Phone2, center.Phone3
                 }
             };
             SmallCenters.Add(smallCenter);
         }
         SmallCenters = SmallCenters.OrderByDescending(c => c.CenterRate).ToList();
         return(new CentersResponse
         {
             Message = Utilities.GetErrorMessages("200"),
             centers = SmallCenters.Skip(skip).Take(count).ToList()
         });
     }
     catch (Exception)
     {
         return(new CentersResponse
         {
             Message = Utilities.GetErrorMessages("500"),
         });
     }
 }
Esempio 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")
         });
     }
 }