public ActionResult Culture() { CustomCultureInfo customCultureInfo = Thread.CurrentThread.CurrentCulture as CustomCultureInfo; CultureModel model = new CultureModel(); model.TimezoneHour = 0; model.CurrentCultureDateTime = DateTimeExtensions.GetCustomCultureDateTime(); model.PricipleDateTime = DateTimeExtensions.GetUserThreadPricipleDateTime(); if (customCultureInfo != null) { model.TimezoneHour = customCultureInfo.UtcHours; } model.Messages.Add(System.Web.HttpContext.Current.Items["culture-begin"] as string); model.Messages.Add(System.Web.HttpContext.Current.Items["culture-end"] as string); model.Messages.Add($"Home-UtcHours:{customCultureInfo?.UtcHours} : {DateTime.Now}"); model.Messages.Add($"CurrentPrincipal-Name:{Thread.CurrentPrincipal.Identity.Name} : {DateTime.Now}"); CustomPrincipal customPrincipal = User as CustomPrincipal; if (customPrincipal != null) { model.Messages.Add($"MyFormsIdentity:{customPrincipal.Identity.Name} : {customPrincipal.TimeZoneHour}"); model.UserDataTimezoneHour = customPrincipal.TimeZoneHour; } model.UserNo = User.Identity?.Name; return(View(model)); }
public HttpResponseMessage Save(CultureModel aCultureModel) { try { if (this.ModelState.IsValid) { var culList = service.SaveCulture(aCultureModel); if (culList != null) { return(Request.CreateResponse(HttpStatusCode.OK, culList)); } else { string message = "Error Saving Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message)); } }
public HttpResponseMessage EditCulture(CultureModel aCultureModel) { try { if (this.ModelState.IsValid) { var culture = service.EditCulture(aCultureModel); if (culture != null) { return(Request.CreateResponse(HttpStatusCode.OK, culture)); } else { string message = "Not updated successfully"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public void IntegrationTest() { var connection = TestSession.GetConnection(); connection.Open(); #region good insertion and select by id test CultureModel inserted = new CultureModel(); inserted.CultureID = TestSession.Random.RandomString(6); inserted.Name = TestSession.Random.RandomString(50); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Insert(connection, new[] { inserted }); var selectedAfterInsertion = _tested.GetByPrimaryKey(connection, new CultureModelPrimaryKey() { CultureID = inserted.CultureID, }); CollectionAssert.IsNotEmpty(selectedAfterInsertion); var selectedAfterInsert = selectedAfterInsertion.Single(); Assert.AreEqual(inserted.CultureID, selectedAfterInsert.CultureID); Assert.AreEqual(inserted.Name, selectedAfterInsert.Name); Assert.AreEqual(inserted.ModifiedDate, selectedAfterInsert.ModifiedDate); #endregion #region update and select by id test inserted.Name = TestSession.Random.RandomString(50); inserted.ModifiedDate = TestSession.Random.RandomDateTime(); _tested.Update(connection, new[] { inserted }); var selectedAfterUpdateAddresss = _tested.GetByPrimaryKey(connection, new CultureModelPrimaryKey() { CultureID = inserted.CultureID, }); CollectionAssert.IsNotEmpty(selectedAfterUpdateAddresss); var selectedAfterUpdate = selectedAfterUpdateAddresss.Single(); Assert.AreEqual(inserted.CultureID, selectedAfterUpdate.CultureID); Assert.AreEqual(inserted.Name, selectedAfterUpdate.Name); Assert.AreEqual(inserted.ModifiedDate, selectedAfterUpdate.ModifiedDate); #endregion #region delete test _tested.Delete(connection, new[] { inserted }); var selectedAfterDeleteAddresss = _tested.GetByPrimaryKey(connection, new CultureModelPrimaryKey() { CultureID = inserted.CultureID, }); CollectionAssert.IsEmpty(selectedAfterDeleteAddresss); #endregion connection.Close(); }
public HttpResponseMessage GetCultures(CultureModel aCultureModel) { //IUnitOfWork uWork = new UnitOfWork(); //ICountryRepository country_repo = new CountryRepository(uWork); //ICountryService country_Service = new CountryService(country_repo); try { //if (this.ModelState.IsValid) //{ // CountryModel aCountryModel = new CountryModel(); // aCountryModel.CurrentCulture = aCultureModel.CurrentCulture; // aCountryModel.CurrentUserID = aCultureModel.CurrentUserID; // var culList = service.GetAllCultureList(aCultureModel); // var countryList = country_Service.GetAllCountryList(aCountryModel); // if (culList != null && countryList !=null) // { // var result = (from c in countryList // join cl in culList on c.Id equals cl.CountryID // select new // { // Id = cl.ID, // Country = c.Name, // Code = cl.Code, // IsActive = cl.IsActive // }).ToList(); // return Request.CreateResponse(HttpStatusCode.OK, result); // } // else // { // string message = "Error in getting Data"; // return Request.CreateErrorResponse(HttpStatusCode.Forbidden, message); // } //} //else //{ // return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); //} var result = service.GetAllCultureList(aCultureModel); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message)); } }
public HttpResponseMessage GetAll() { try { if (this.ModelState.IsValid) { var culList = service.GetAll(); List <CultureModel> cultures = new List <CultureModel>(); if (culList != null) { foreach (var culture in culList) { var c = new CultureModel(); c.ID = culture.ID; c.CountryID = culture.CountryID; c.Code = culture.Code; c.Name = culture.Description; c.SortBy = culture.SortBy; cultures.Add(c); } cultures = cultures.OrderBy(o => o.SortBy).ToList(); return(Request.CreateResponse(HttpStatusCode.OK, cultures)); } else { string message = "Error in getting Data"; return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, message)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message)); } }
public IHttpActionResult GetLeague(int id, string ln) { CultureModel.ChangeCulture(ln); League league = db.Leagues.Find(id); if (league == null) { return(NotFound()); } int?currentSeasonId = league.SeasonId; LeagueRankService lrsvc = new LeagueRankService(id); LeaguePageVeiwModel vm = new LeaguePageVeiwModel(); //League Info vm.LeagueInfo = new LeagueInfoVeiwModel(league); //var teamWithMostFans = league.Teams.OrderByDescending(t => t.TeamsFans.Where(tf => tf.LeageId == id).Count()).FirstOrDefault(); //Team with the most fans var teamRepo = new TeamsRepo(); var topTeamTuple = teamRepo.GetByMostFans(league.LeagueId); var topTeam = topTeamTuple == null ? null : teamRepo.GetById(topTeamTuple.Item1); if (topTeam != null) { vm.TeamWithMostFans = new TeamCompactViewModel { FanNumber = topTeamTuple.Item2, TeamId = topTeam.TeamId, Logo = topTeam.Logo, Title = topTeam.Title, LeagueId = league.LeagueId }; } var leagueGames = db.GamesCycles.Include(t => t.Auditorium) .Include(t => t.GuestTeam) .Include(t => t.HomeTeam) .Where(gc => gc.Stage.LeagueId == id && gc.IsPublished).ToList(); //Next Game vm.NextGame = GamesService.GetNextGame(leagueGames, base.CurrUserId, id, currentSeasonId); //List of all next games if (vm.NextGame != null) { vm.NextGames = GamesService.GetNextGames(leagueGames, vm.NextGame.StartDate, currentSeasonId); } //List of all last games vm.LastGames = GamesService.GetLastGames(leagueGames, currentSeasonId); //League table var rLeague = lrsvc.CreateLeagueRankTable(currentSeasonId); if (rLeague != null) { vm.LeagueTableStages = rLeague.Stages; // lrsvc.CreateLeagueRankTable(currentSeasonId).Stages; MakeGroupStages(vm.LeagueTableStages, isEmpty: false); } if (vm.LeagueTableStages == null || vm.LeagueTableStages.Count == 0) { vm.LeagueTableStages = lrsvc.CreateEmptyRankTable(currentSeasonId).Stages; MakeGroupStages(vm.LeagueTableStages, isEmpty: true); } vm.GameCycles = leagueGames.Select(gc => gc.CycleNum).Distinct().OrderBy(c => c).ToList(); vm.LeagueTableStages = vm.LeagueTableStages.Where(x => x.Groups.All(y => !y.IsAdvanced)).ToList(); return(Ok(vm)); }
public IHttpActionResult Rank(int id, string ln) { CultureModel.ChangeCulture(ln); var leagueRank = new LeagueRank { Stages = new List <StageRank>() }; int?seasonId = seasonsRepo.GetLastSeasonByLeagueId(id); LeagueRankService svc = new LeagueRankService(id); RankLeague rLeague = svc.CreateLeagueRankTable(seasonId) ?? new RankLeague(); foreach (var stage in rLeague.Stages) { if (stage.Groups.All(g => g.IsAdvanced)) { continue; } var rankStage = new StageRank(); var nameStage = ""; if (stage.Groups.Any() && stage.Groups.All(g => g.IsAdvanced)) { var firstGroup = stage.Groups.FirstOrDefault(); if (firstGroup != null && firstGroup.PlayoffBrackets != null) { int numOfBrackets = (int)firstGroup.PlayoffBrackets; switch (numOfBrackets) { case 1: nameStage = Messages.Final; break; case 2: nameStage = Messages.Semifinals; break; case 4: nameStage = Messages.Quarter_finals; break; case 8: nameStage = Messages.Final_Eighth; break; default: nameStage = (numOfBrackets * 2) + Messages.FinalNumber; break; } } } else { nameStage = Messages.Stage + stage.Number; } rankStage.NameStage = nameStage; rankStage.Groups = new List <GroupRank>(); foreach (var group in stage.Groups) { var rankGroup = new GroupRank { NameGroup = @group.Title, Teams = new List <TeamRank>() }; for (var i = 0; i < group.Teams.Count(); i++) { var rankTeam = new TeamRank { Team = @group.Teams[i].Title, Logo = @group.Teams[i].Logo }; int numOfBrackets = (int)group.PlayoffBrackets; rankTeam.Position = i % (numOfBrackets) == 0 ? (i + 1).ToString() : "-"; rankGroup.Teams.Add(rankTeam); } rankStage.Groups.Add(rankGroup); } leagueRank.Stages.Add(rankStage); } return(Ok(leagueRank)); }