public int InsertCourt( BasketballCourt entity) { using (var dbContext = new DataModelDbContext()) { dbContext.BasketballCourts.Add(entity).Entity.Uid = Guid.NewGuid(); return(dbContext.SaveChanges()); } }
public BasketballCourt GetCourt( Guid uid) { using (var dbContext = new DataModelDbContext()) { return(GetCourts(dbContext) .Where(c => c.Uid == uid) .SingleOrDefault()); } }
public byte[] GetSnapshot( Guid uid, int index) { using (var dbContext = new DataModelDbContext()) { return(dbContext.Snapshots .Where(t => t.CourtUid == uid && t.Index == index) .Select(t => t.Content) .SingleOrDefault()); } }
public IEnumerable <QuestionList> GetQuestionList() { //List<QuestionList> employeeList = new List<QuestionList>(); //DataModelDbContext dc = new DataModelDbContext(); // List <QuestionList> ee = null; using (DataModelDbContext dc = new DataModelDbContext()) { // yield return dc.QuestionLists.FirstOrDefault(e => e.QuestionType =="22"); return(dc.QuestionLists.ToList()); // return ee; // yield return dc.QuestionLists.ToList(); } }
public IEnumerable <BasketballCourt> GetCourtsInside( decimal swLat, decimal swLng, decimal neLat, decimal neLng) { using (var dbContext = new DataModelDbContext()) { return(GetCourts(dbContext) .Where(c => swLat <= c.Latitude && c.Latitude <= neLat && swLng <= c.Longitude && c.Longitude <= neLng) .ToList()); } }
// GET: api/CollegeDetails public QuestionList savequestiondetails() { QuestionList ee = new QuestionList(); ee.Question = "abcd"; ee.QuestionType = "3"; //ee.QuestionType = "2"; using (DataModelDbContext dbContext = new DataModelDbContext()) { dbContext.QuestionLists.Add(ee); dbContext.SaveChanges(); } return(ee); }
public IEnumerable <Rating> GetRatingByCourt <TSortKey>( Guid courtUid, int take, int skip, Func <Rating, TSortKey> sortSelector, IComparer <TSortKey> sortComparer) { using (var dbContext = new DataModelDbContext()) { return(GetRatings(dbContext) .Where(r => r.Court.Uid == courtUid) .OrderBy(sortSelector, sortComparer) .Skip(skip) .Take(take) .ToList()); } }
public int SaveReview( Rating entity) { using (var dbContext = new DataModelDbContext()) { Rating existing = dbContext.Ratings.AsNoTracking() .Where(r => r.CourtUid == entity.CourtUid && r.PlayerUid == entity.PlayerUid) .SingleOrDefault(); if (existing != null) { dbContext.Ratings.Update(entity); } else { dbContext.Ratings.Add(entity); } return(dbContext.SaveChanges()); } }
public IEnumerable <ICourtReview> GetCourtReview( Guid uid, int page, int size, CourtReviewSortDirections sort) { using (var dbContext = new DataModelDbContext()) { var direction = (sort == CourtReviewSortDirections.HighestFirst ? -1 : 1); var comparer = Comparer <RatingScores> .Create((x, y) => direction *((int)x <(int)y ? -1 : (int)x> (int) y ? 1 : 0)); List <CourtReview> result = _dataAccess.GetRatingByCourt( uid, size, (page - 1) * size, r => r.Score, comparer) .Select(_mapper.Map <Rating, CourtReview>) .ToList(); return(result); } }
public void TestShiftBlockAPI() { DataModelDbContext db = new DataModelDbContext(); Business business = db.Businesses.FirstOrDefault(b => b.Name == "Bar Rumba"); Role role = db.Roles.FirstOrDefault(r => r.Business.Id == business.Id); Random rnd = new Random(); int rHourStart = rnd.Next(4, 14); //Rand start hour between 4 and 14 int rMinStart = rnd.Next(0, 60); //Rand start hour between 0 and 60 ShiftBlockDTO sbDTO = new ShiftBlockDTO { StartTime = new TimeSpan(rHourStart, rMinStart, 0), FinishTime = new TimeSpan(20, 0, 0), //set finish time of 8pm FinishNextDay = false, BusinessId = business.Id, RoleId = role.Id }; var shiftBlocksbeforeAdd = shiftBlockAPIController.GetShiftBlocks(business.Id); shiftBlockAPIController.Post(sbDTO); var shiftBlocksAfterAdd = shiftBlockAPIController.GetShiftBlocks(business.Id); Assert.IsTrue(shiftBlocksAfterAdd.Count() == (shiftBlocksbeforeAdd.Count() + 1), "Shift block has not been saved correctly"); var obj1 = shiftBlocksAfterAdd.Where(sb => sb.StartTime == new TimeSpan(rHourStart, rMinStart, 0) && sb.FinishTime == new TimeSpan(20, 0, 0)) .FirstOrDefault(); Assert.IsNotNull(obj1); //Test Get single DTO var obj2 = shiftBlockAPIController.Get(obj1.Id); Assert.IsNotNull(obj2); Assert.IsTrue(obj2.StartTime == sbDTO.StartTime && obj2.FinishTime == sbDTO.FinishTime && obj2.FinishNextDay == sbDTO.FinishNextDay && obj2.BusinessId == sbDTO.BusinessId && obj2.RoleId == sbDTO.RoleId, "Objects do not match"); //Test Update obj2.StartTime = new TimeSpan(rHourStart + 1, rMinStart, 0); obj2.FinishTime = new TimeSpan(2, 0, 0); obj2.FinishNextDay = true; shiftBlockAPIController.Put(obj2.Id, obj2); //Test Get again to verify changes DTO var obj3 = shiftBlockAPIController.Get(obj1.Id); Assert.IsTrue(obj3.StartTime == new TimeSpan(rHourStart + 1, rMinStart, 0) && obj2.FinishTime == new TimeSpan(2, 0, 0) && obj2.FinishNextDay == true, "Update did not work"); shiftBlockAPIController.Delete(obj1.Id); var shiftBlocksAfterDelete = shiftBlockAPIController.GetShiftBlocks(business.Id); Assert.IsTrue(shiftBlocksAfterDelete.Count() == shiftBlocksbeforeAdd.Count(), "Shift block has not been deleted correctly"); //Test Get single DTO after delete bool exceptionThrown = false; try { var obj4 = shiftBlockAPIController.Get(obj1.Id); } catch (Exception ex) { exceptionThrown = true; var mg = ex.Message; } Assert.IsTrue(exceptionThrown, "Exception not thrown when getting deleted item"); }
internal static IEnumerable <Rating> GetRatings( DataModelDbContext dbContext) => dbContext.Ratings .Include(c => c.Court) .Include(c => c.Player);
internal static IQueryable <BasketballCourt> GetCourts( DataModelDbContext dbContext) => dbContext.BasketballCourts .Include(c => c.Ratings) .ThenInclude(c => c.Player);
public void TestUserPrefAPI() { DataModelDbContext db = new DataModelDbContext(); var userPrefs = userPrefAPIController.GetPreferencesForCurrentUser(); }