public IActionResult UpdateSportEvent(int id, [FromBody] SportEventDTO sportEvent) { if (sportEvent == null || sportEvent.SportEventId != id) { return(BadRequest()); } var sportEventToUpdate = _manager.ViewSportEvent(id); if (sportEventToUpdate == null) { return(NotFound()); } var se = _mapper.Map <SportEvent>(sportEvent); try { _manager.EditSportEvent(se); } catch (Exception) { return(BadRequest("Delete sportevent not allowed")); } return(Ok("SportEvent updated")); }
public IEnumerable <SportEventDTO> GetCreatedByPage(int pageSize, int pageNumber, int userId) { using (var uow = new UnitOfWork()) { var sportEventRepository = uow.GetRepository <SportEvent>(); var accountRepository = uow.GetRepository <Account>(); var account = accountRepository.GetById(userId); var sportEvents = sportEventRepository.FindBy(spev => spev.OwnerId == account.Id); var totalCount = sportEvents.Count(); var totalPages = Math.Ceiling((double)totalCount / pageSize); sportEvents = sportEvents.OrderByDescending(s => s.Date); var sportsev = sportEvents.Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToList(); List <SportEventDTO> list = new List <SportEventDTO>(); SportEventMapper sportEventMapper = new SportEventMapper(); foreach (var se in sportsev) { SportEventDTO sportEventVM = sportEventMapper.MapToDTO(se); list.Add(sportEventVM); } return(list); } }
public IEnumerable <SportEventDTO> GetNearByPage(int pageSize, int pageNumber, float lat, float lng) { using (var uow = new UnitOfWork()) { var sportEventRepository = uow.GetRepository <SportEvent>(); var sportEvents = sportEventRepository.FindBy(spev => spev.Adress.latitude > (lat - 1) & spev.Adress.latitude <(lat + 1) & spev.Adress.longitude> (lng - 1) & spev.Adress.longitude < (lng + 1)); var totalCount = sportEvents.Count(); var totalPages = Math.Ceiling((double)totalCount / pageSize); sportEvents = sportEvents.OrderByDescending(s => s.Date); var sportsev = sportEvents.Skip((pageNumber - 1) * pageSize) .Take(pageSize) .ToList(); List <SportEventDTO> list = new List <SportEventDTO>(); SportEventMapper sportEventMapper = new SportEventMapper(); foreach (var se in sportsev) { SportEventDTO sportEventVM = sportEventMapper.MapToDTO(se); list.Add(sportEventVM); } return(list); } }
public void NullTeamsSportEventsSaving() { ResultDTO r1 = new ResultDTO { TeamName = "Ворскла", IsHome = false, Score = 0 }; ResultDTO r2 = new ResultDTO { TeamName = "Металлист", IsHome = true, Score = 4 }; SportEventDTO ev = new SportEventDTO { Date = DateTime.Now.Ticks, SportType = "Football", Results = new List <ResultDTO> { r1, r2 } }; List <SportEventDTO> events = new List <SportEventDTO>(); events.Add(ev); IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext); this.eventService.SaveSportEvents(events); Team team1 = unit.GetRepository <TeamName>().Get(tn => tn.Name == "Металлист").Select(tn => tn.Team).FirstOrDefault(); Assert.IsNotNull(team1); Team team2 = unit.GetRepository <TeamName>().Get(tn => tn.Name == "Ворскла").Select(tn => tn.Team).FirstOrDefault(); Assert.IsNotNull(team2); Result savedResult1 = unit.GetRepository <Result>().Get(r => r.Team.Id == team1.Id).FirstOrDefault(); Assert.IsNotNull(savedResult1); Result savedResult2 = unit.GetRepository <Result>().Get(r => r.Team.Id == team2.Id).FirstOrDefault(); Assert.IsNotNull(savedResult2); SportEvent savedEvent1 = unit.GetRepository <Result>() .Get(filter: r => r.SportEvent.Id == savedResult1.SportEvent.Id) .Select(r => r.SportEvent).FirstOrDefault(); Assert.IsTrue(savedEvent1.Results.Contains(savedResult2)); IEnumerable <TempResult> tempResults = unit.GetRepository <TempResult>().Get(); Assert.IsEmpty(tempResults); IEnumerable <TempSportEvent> tempEvents = unit.GetRepository <TempSportEvent>().Get(); Assert.IsEmpty(tempEvents); IEnumerable <Conformity> conformities = unit.GetRepository <Conformity>().Get(); Assert.IsEmpty(conformities); }
public void OneConformitySportEventsSaving() { ResultDTO r1 = new ResultDTO { TeamName = "Динамо Киев", IsHome = true, Score = 3 }; ResultDTO r2 = new ResultDTO { TeamName = "Ст. Этьен", IsHome = false, Score = 1 }; SportEventDTO ev = new SportEventDTO { Date = DateTime.Now.Ticks, SportType = "Football", Results = new List <ResultDTO> { r1, r2 } }; List <SportEventDTO> events = new List <SportEventDTO>(); events.Add(ev); IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext); this.eventService.SaveSportEvents(events); Team team1 = unit.GetRepository <TeamName>() .Get(tn => tn.Name == "Динамо Киев") .Select(tn => tn.Team) .FirstOrDefault(); Assert.IsNotNull(team1); Team team2 = unit.GetRepository <TeamName>().Get(tn => tn.Name == "Ст. Этьен").Select(tn => tn.Team).FirstOrDefault(); Assert.IsNull(team2); IEnumerable <SportEvent> emptyEvents = unit.GetRepository <SportEvent>().Get(e => e.Results.Count() == 0); Assert.IsTrue(emptyEvents.Count() == 0); IEnumerable <SportEvent> oneResultEvents = unit.GetRepository <SportEvent>().Get(e => e.Results.Count() == 1); Assert.IsTrue(oneResultEvents.Count() == 0); Conformity conf2 = unit.GetRepository <Conformity>().Get(c => c.InputName == "Ст. Этьен").FirstOrDefault(); Assert.IsTrue(conf2.TempResult != null); Assert.IsTrue(conf2.TempResult.Team == null); IEnumerable <TempResult> tempResults = unit.GetRepository <TempResult>().Get(); Assert.IsTrue(tempResults.Count() == 2); TempResult tempResult1 = unit.GetRepository <TempResult>().Get(r => r.Team != null).FirstOrDefault(); Assert.IsTrue(tempResult1.Team.Name == "Динамо Киев"); Assert.IsTrue(conf2.TempResult.TempSportEvent.Id == tempResult1.TempSportEvent.Id); }
public void BothConformitiesSportEventsSaving() { ResultDTO r1 = new ResultDTO { TeamName = "Маккаби Тель-Авив", IsHome = true, Score = 2 }; ResultDTO r2 = new ResultDTO { TeamName = "Ст. Этьен", IsHome = false, Score = 1 }; SportEventDTO ev = new SportEventDTO { Date = DateTime.Now.Ticks, SportType = "Football", Results = new List <ResultDTO> { r1, r2 } }; List <SportEventDTO> events = new List <SportEventDTO>(); events.Add(ev); IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext); this.eventService.SaveSportEvents(events); Team team1 = unit.GetRepository <TeamName>() .Get(tn => tn.Name == "Маккаби Тель-Авив") .Select(tn => tn.Team) .FirstOrDefault(); Assert.IsNull(team1); Team team2 = unit.GetRepository <TeamName>().Get(tn => tn.Name == "Ст. Этьен").Select(tn => tn.Team).FirstOrDefault(); Assert.IsNull(team2); IEnumerable <SportEvent> simpleEvents = unit.GetRepository <SportEvent>().Get(e => e.Results.Count() == 0); Assert.IsTrue(simpleEvents.Count() == 0); Conformity conf1 = unit.GetRepository <Conformity>().Get(c => c.InputName == "Маккаби Тель-Авив").FirstOrDefault(); Assert.IsNotNull(conf1); Conformity conf2 = unit.GetRepository <Conformity>().Get(c => c.InputName == "Ст. Этьен").FirstOrDefault(); Assert.IsNotNull(conf2); IEnumerable <TempResult> tempResults = unit.GetRepository <TempResult>().Get(); Assert.IsTrue(tempResults.Count() == 2); IEnumerable <TempSportEvent> tempEvents = unit.GetRepository <TempSportEvent>().Get(); Assert.IsTrue(tempEvents.Count() == 1); }
public static IEnumerable <Link> GetLinks(this SportEventDTO se) { return(new[] { new Link("self", "/api/sportevents/" + se.SportEventId, null, "GET"), new Link("self", "/api/sportevents/" + se.SportEventId, null, "DELETE"), new Link("self", "/api/sportevents/" + se.SportEventId, null, "PUT"), new Link("reservation", "/api/reservations/" + se.ReservationId, null, "GET"), new Link("sport", "/api/sports/" + se.SportId, null, "GET") }); }
public IHttpActionResult Post(SportEventDTO sportevent) { var sportEventService = new SportEventService(); SportEventDTO sporteventVM = sportEventService.addSportEvent(sportevent); if (sportevent == null) { return(NotFound()); } return(Ok(sportevent)); }
public SportEventDTO addSportEvent(SportEventDTO sporteventVM) { using (var uow = new UnitOfWork()) { var sportEventRepository = uow.GetRepository <SportEvent>(); var adressRepository = uow.GetRepository <Adress>(); var sportRepository = uow.GetRepository <Sport>(); var accountRepository = uow.GetRepository <Account>(); AdressService addressService = new AdressService(); SportService sportService = new SportService(); AccountService accountService = new AccountService(); SportEventMapper sportEventMapper = new SportEventMapper(); SportEvent sportEvent = sportEventMapper.MapFromDTO(sporteventVM); var queryAddress = adressRepository.FindBy(ad => ad.latitude == sportEvent.Adress.latitude | ad.longitude == sportEvent.Adress.longitude); var existAd = queryAddress.FirstOrDefault(); if (existAd != null) { sportEvent.Adress = existAd; } var queryCategory = sportRepository.FindBy(sp => sp.Name == sportEvent.Category.Name); var existCategory = queryCategory.FirstOrDefault(); if (existCategory != null) { sportEvent.Category = existCategory; } var queryOwner = accountRepository.FindBy(ac => ac.UserName == sportEvent.Owner.UserName | ac.Email == sportEvent.Owner.Email); var existOwner = queryOwner.FirstOrDefault(); if (existOwner != null) { sportEvent.Owner = existOwner; } sportEvent = sportEventRepository.Add(sportEvent); uow.SaveChanges(); return(sportEventMapper.MapToDTO(sportEvent)); } }
public IHttpActionResult Get(int id) { var sportEventService = new SportEventService(); SportEventDTO sporteventVM = sportEventService.getSportEventBy(id); if (sporteventVM == null) { return(NotFound()); } return(Ok(sporteventVM)); }
public void DoubleConformitySportEventsSaving() //multiple conformities with the same inputName { ResultDTO r1 = new ResultDTO { TeamName = "Динамо", IsHome = true, Score = 0 }; ResultDTO r2 = new ResultDTO { TeamName = "Манчестер Юнайтед", IsHome = false, Score = 1 }; SportEventDTO ev1 = new SportEventDTO { Date = DateTime.Now.Ticks, SportType = "Football", Results = new List <ResultDTO> { r1, r2 } }; List <SportEventDTO> events = new List <SportEventDTO>(); events.Add(ev1); IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext); this.eventService.SaveSportEvents(events); Team team1 = unit.GetRepository <TeamName>().Get(tn => tn.Name == "Динамо").Select(tn => tn.Team).FirstOrDefault(); Assert.IsNull(team1); Team team2 = unit.GetRepository <TeamName>() .Get(tn => tn.Name == "Манчестер Юнайтед") .Select(tn => tn.Team) .FirstOrDefault(); Assert.IsNotNull(team2); IEnumerable <SportEvent> simpleEvents = unit.GetRepository <SportEvent>().Get(e => e.Results.Count() == 0); Assert.IsTrue(simpleEvents.Count() == 0); IEnumerable <Conformity> confs = unit.GetRepository <Conformity>().Get(c => c.InputName == "Динамо"); Assert.IsTrue(confs.Count() == 2); IEnumerable <TempResult> tempResults = unit.GetRepository <TempResult>().Get(); Assert.IsTrue(tempResults.Count() == 2); IEnumerable <TempSportEvent> tempEvents = unit.GetRepository <TempSportEvent>().Get(); Assert.IsTrue(tempEvents.Count() == 1); }
public SportEventDTO getSportEventBy(int id) { using (var uow = new UnitOfWork()) { var sportEventsRepository = uow.GetRepository <SportEvent>(); var sportEvent = sportEventsRepository.GetById(id); if (sportEvent == null) { return(null); } SportEventMapper sportEventMapper = new SportEventMapper(); SportEventDTO sportEventVM = sportEventMapper.MapToDTO(sportEvent); return(sportEventVM); } }
public List <SportEventDTO> GetSportEventsList(JsonResult result) { List <SportEventDTO> eventList = new List <SportEventDTO>(); List <ResultDTO> resultList; string sportType; try { foreach (var ev in result.Events) { resultList = new List <ResultDTO>(); Sport sport = result.Sports .Where(n => result.Sections.Where(s => s.Events.Contains(ev.Id)) .FirstOrDefault().Sport == n.Id).FirstOrDefault(); if (sport != null) { sportType = sport.Name; if (this.GetTeamsNamesFromEvent(ev, sportType, resultList) && this.AcceptSportType(this.ChangeSportTypeName(Locale.RU, sportType))) { if (ev.Status == (int)EventStatus.Finished) { this.GetScoresFromEvent(ev, resultList); } SportEventDTO sportEvent = new SportEventDTO(); sportEvent.Date = this.UnixToDateTime(ev.StartTime).Ticks; sportEvent.Results = resultList; sportEvent.SportType = this.ChangeSportTypeName(Locale.RU, sportType); eventList.Add(sportEvent); } } } } catch (Exception ex) { throw new ParseException(ex.Message, ex.InnerException); } return(eventList); }
public IEnumerable <SportEventDTO> getAllEvents() { using (var uow = new UnitOfWork()) { var sportEventsRepository = uow.GetRepository <SportEvent>(); var sportEvents = sportEventsRepository.GetAll().ToList(); List <SportEventDTO> list = new List <SportEventDTO>(); SportEventMapper sportEventMapper = new SportEventMapper(); foreach (var sportEvent in sportEvents) { SportEventDTO sportEventVM = sportEventMapper.MapToDTO(sportEvent); list.Add(sportEventVM); } return(list); } }
public IEnumerable <SportEventDTO> getSportEventsInterested(List <int> sportsId) { using (var uow = new UnitOfWork()) { var sportEventRepository = uow.GetRepository <SportEvent>(); var sportEvents = sportEventRepository.FindBy(sp => sportsId.Contains(sp.CategoryId)); List <SportEventDTO> list = new List <SportEventDTO>(); SportEventMapper sportEventMapper = new SportEventMapper(); foreach (var sportEvent in sportEvents) { SportEventDTO sportEventVM = sportEventMapper.MapToDTO(sportEvent); list.Add(sportEventVM); } return(list); } }
public IActionResult CreateSportEvent([FromBody] SportEventDTO sportEvent) { if (sportEvent == null) { return(BadRequest()); } var se = _mapper.Map <SportEvent>(sportEvent); try { _manager.AddSportEvent(se); } catch (Exception) { BadRequest("Add sportevent not allowed"); } return(CreatedAtRoute("getsportevent", new { id = se.SportEventId }, _mapper.Map <SportEventDTO>(se))); }
public SportEvent MapFromDTO(SportEventDTO source) { SportEvent target = new SportEvent(); AccountMapper accountMapper = new AccountMapper(); target.Owner = accountMapper.MapFromDTO(source.Owner); AdressMapper adressMapper = new AdressMapper(); target.Adress = adressMapper.MapFromDTO(source.Adress); SportMapper sportMapper = new SportMapper(); target.Category = sportMapper.MapFromDTO(source.Category); target.Id = source.Id; target.Date = source.Date; target.Description = source.Description; target.Title = source.Title; target.ImagePath = source.ImagePath; return(target); }
private List <SportEventDTO> ParseHtml(string html, string currentSport, long date) { var parser = new HtmlParser(); var document = parser.Parse(html); List <SportEventDTO> events = new List <SportEventDTO>(); try { foreach (IElement htmlTr in document.QuerySelectorAll(".daymatches tr[class]:not(.hidden)")) { SportEventDTO currentEvent = new SportEventDTO() { Date = date, SportType = currentSport }; string teamName1 = htmlTr.Children[1].FirstElementChild.TextContent; string teamName2 = htmlTr.Children[2].FirstElementChild.TextContent; var score = htmlTr.QuerySelectorAll("span[id*='score']")[0].TextContent; score = score.Replace("\n", string.Empty).Replace("\t", string.Empty); score = score.Split('(')[0]; int score1; int score2; ResultDTO result1 = new ResultDTO { TeamName = teamName1, IsHome = true }; ResultDTO result2 = new ResultDTO { TeamName = teamName2, IsHome = false }; if (score.Contains(":")) { var scores = score.Split(':'); int.TryParse(scores[0], out score1); int.TryParse(scores[1], out score2); result1.Score = score1; result2.Score = score2; } else if (score.Contains("— —")) { result1.Score = null; result2.Score = null; } else { continue; } currentEvent.Results.Add(result1); currentEvent.Results.Add(result2); events.Add(currentEvent); } } catch (Exception ex) { throw new ParseException(ex.Message, ex.InnerException); } return(events); }