//Get events nearby //Input: PointDTO, radius //Output: List of MapEventDTO public static List <MapEventDTO> GetEvents(PointDTO position, double radius) { SwapDbConnection db = new SwapDbConnection(); PointDTO point = new PointDTO(); List <Event> Allevents = db.Events.Where(e => e.end_date > DateTime.Now).ToList(); List <MapEventDTO> FilteredEvents = new List <MapEventDTO>(); foreach (Event e in Allevents) { point.lat = (double)e.place.latitude; point.lng = (double)e.place.longitude; if (PlaceService.GetDistance(point, position) <= radius) { FilteredEvents.Add(new MapEventDTO { description = e.place.description ?? "", end_date = e.end_date, name = e.place.name ?? "", place_id = e.place_id, price = e.price, start_date = e.start_date, lat = e.place.latitude, lng = e.place.longitude, settlement = e.place.settlement ?? "", street = e.place.street ?? "", street_number = e.place.street_number ?? "" }); } } return(FilteredEvents); }
public IHttpActionResult Update([FromBody] PointDTO pointDTO) { var point = pointDTO.ToPointUpdate(_pointsBiz); _pointsBiz.Update(point); return(Ok(_pointsBiz.GetById(point.Id))); }
public IHttpActionResult Add([FromBody] PointDTO pointDTO) { var point = pointDTO.ToPoint(); _pointsBiz.Create(point); return(Created(string.Format("{0}/{1}", Request.RequestUri, point.Id), point)); }
public static void Create(PointDTO pointDTO) { Point point = MapperTransform <Point, PointDTO> .ToEntity(pointDTO); Database.Points.Create(point); Database.Save(); }
public JsonAnswer(PointDTO task, int UserId = 0) : base(task, UserId) { Answer = task.Address; Position = new double[2] { task.Latitude, task.Longitude }; }
//Get businesses nearby and filtered by categories //Input: PointDTO, CategoriesIdsDTO, radius //Output: List of MapBusinessDTO public static List <MapBusinessDTO> GetFilteredBusinessesAround(PointDTO position, CategoriesIdsDTO ids, double radius) { SwapDbConnection db = new SwapDbConnection(); PointDTO point; List <business> businesses; List <MapBusinessDTO> filteredBusinesses = new List <MapBusinessDTO>(); main_category mainCategory = db.main_category.FirstOrDefault(category => category.main_id == ids.mainId); string iconCategory; if (mainCategory == null) { return(filteredBusinesses); } point = new PointDTO(); businesses = db.businesses.Include(b => b.products).Where(b => b.is_active && b.approve_by_admin && b.place.r_place_sub_and_main_category.Any(r => r.main_id == ids.mainId && ids.subIds.Any(id => r.sub_id == id))).ToList(); iconCategory = mainCategory.google_value; foreach (business b in businesses) { point.lat = (double)b.place.latitude; point.lng = (double)b.place.longitude; if (PlaceService.GetDistance(point, position) <= radius) { filteredBusinesses.Add(new MapBusinessDTO { closing_hours = b.closing_hours, description = b.place.description, lat = b.place.latitude, lng = b.place.longitude, name = b.place.name ?? "", opening_hours = b.opening_hours, place_id = b.place_id, rating = b.rating, settlement = b.place.settlement ?? "", street = b.place.street ?? "", street_number = b.place.street_number ?? "", icon = iconCategory ?? "", products = b.products.Where(p => p.is_active && p.discount_end_date >= DateTime.Now).Select(product => new productDTO { business_id = product.business_id, creation_date = product.creation_date, description = product.description, discount = product.discount, discount_end_date = product.discount_end_date, discount_start_date = product.discount_start_date, is_active = product.is_active, name = product.name, price = product.price, product_id = product.product_id }).ToList() }); } } return(filteredBusinesses); }
private void validateExceptionThrownOnUpdateWithBadArgument(PointDTO point) { var thrownException = Assert.Throws <ArgumentException>(() => this.pointsAdminService.UpdatePoint(point)); // assertions this.pointsRepository.DidNotReceive().Save(Arg.Any <PointDTO>()); Assert.That(thrownException.Message, Is.EqualTo("Point Id must be an integer greater than 0.")); }
private PointDTO ConvertPointInPointDto(Point point) { PointDTO pointDTO = new PointDTO(); pointDTO.PointX = point.PointX; pointDTO.PointY = point.PointY; return(pointDTO); }
public void UpdatePointNegativeIdTest() { PointDTO point = new PointDTO() { Id = -1, Name = "Test" }; this.validateExceptionThrownOnUpdateWithBadArgument(point); }
public void GetPointTestNegativeIdTest() { this.pointsRepository.Get(Arg.Any <int>()).Returns((PointDTO)null); PointDTO point = this.pointsConsumerService.GetPoint(-1); PointDTO expectedResult = null; // assertions this.pointsRepository.DidNotReceive().Get(-1); Assert.AreEqual(point, expectedResult); }
public void GetPointTest() { this.pointsRepository.Get(Arg.Any <int>()).Returns(this.getMockedPoints().ElementAt(0)); PointDTO point = this.pointsConsumerService.GetPoint(5); PointDTO expectedResult = this.getMockedPoints().ElementAt(0); // assertions this.pointsRepository.Received().Get(5); Assert.AreEqual(point, expectedResult); }
/// <summary> /// Returns a specific point. /// </summary> /// <param name="pointId">The point Id</param> /// <returns>The requested point. If point does not exist, returns null.</returns> public PointDTO GetPoint(int pointId) { PointDTO point = null; if (pointId > 0) { point = this.pointsRepository.Get(pointId); } return(point); }
public void CreatePointTest() { PointDTO point = new PointDTO() { Name = "Test" }; this.pointsAdminService.CreatePoint(point); // assertions this.pointsRepository.Received().Save(point); }
public static void Update(PointDTO pointDTO) { Point point = Database.Points.Get(pointDTO.Id); point.Latitude = pointDTO.Latitude; point.Address = pointDTO.Address; point.Longitude = pointDTO.Longitude; point.QuestId = pointDTO.QuestId; point.Task = pointDTO.Task; Database.Points.Update(point); Database.Save(); }
public async Task <IActionResult> Post([FromBody] PointDTO dto) { var command = new CreatePointCommand(UserId, dto.Time); await _mediator.Send(command); if (HasNotifications()) { return(BadRequest(LoadErrorMessages())); } return(Ok()); }
public JsonTask(PointDTO task, int UserId = 0) { Id = task.Id; Ask = task.Task; Date = DateTime.Now; DateString = Date.ToString("dd.MM.yyyy HH:mm:ss"); UserAnswer = null; if (UserId != 0) { this.UserId = UserId; } }
//Get distance in meteres from two geolocation points //Input: PointDTO startPosition, PointDTO endPosition //Output: distance in meters public static double GetDistance(PointDTO startPosition, PointDTO endPosition) { int R = 6378137; // Earth’s mean radius in meter double dLat = Radian.DegreesToRadians(endPosition.lat - startPosition.lat); double dLong = Radian.DegreesToRadians(endPosition.lng - startPosition.lng); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(Radian.DegreesToRadians(startPosition.lat)) * Math.Cos(Radian.DegreesToRadians(endPosition.lat)) * Math.Sin(dLong / 2) * Math.Sin(dLong / 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double d = R * c; return(d); // returns the distance in meter }
public void CreatePointWithIdTest() { PointDTO point = new PointDTO() { Id = 5, Name = "Test" }; var thrownException = Assert.Throws <ArgumentException>(() => this.pointsAdminService.CreatePoint(point)); // assertions this.pointsRepository.DidNotReceive().Save(Arg.Any <PointDTO>()); Assert.That(thrownException.Message, Is.EqualTo("Point Id is assigned automatically. Cannot create point with the Id assigned.")); }
/// <summary> /// Creates a new point. /// </summary> /// <param name="point">The point data.</param> /// <returns>The created point.</returns> public PointDTO CreatePoint(PointDTO point) { PointDTO savedPoint = null; if (point.Id == 0) { savedPoint = this.pointsRepository.Save(point); } else { throw new ArgumentException("Point Id is assigned automatically. Cannot create point with the Id assigned."); } return(savedPoint); }
/// <summary> /// Updates an existing point. /// </summary> /// <param name="point">The new point data.</param> /// <returns>The updated point.</returns> public PointDTO UpdatePoint(PointDTO point) { PointDTO savedPoint = null; if (point.Id > 0) { savedPoint = this.pointsRepository.Save(point); } else { throw new ArgumentException("Point Id must be an integer greater than 0."); } return(savedPoint); }
public HttpResponseMessage GetFilteredBusinesses([FromUri] PointDTO position, [FromUri] CategoriesIdsDTO ids, double radius) { try { if (string.IsNullOrEmpty(ids.mainId) || ids.subIds == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Illegal parameters")); } List <MapBusinessDTO> list = BusinessService.GetFilteredBusinessesAround(position, ids, radius); return(Request.CreateResponse(HttpStatusCode.OK, list)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e)); } }
public HttpResponseMessage GetEvents([FromUri] PointDTO point, double radius) { try { if (point == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Illegal Parameters")); } List <MapEventDTO> list = EventsService.GetEvents(point, radius); return(Request.CreateResponse(HttpStatusCode.OK, list)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e)); } }
public PointDTO Get(int id) { PointDTO point = this.pointsConsumerService.GetPoint(id); if (point == null) { HttpResponseMessage message = new HttpResponseMessage() { Content = new StringContent("Point Id not found."), StatusCode = HttpStatusCode.BadRequest }; throw new HttpResponseException(message); } return(point); }
public PointDTO Get(int pointId) { PointDTO point = null; using (var dbContext = new DeliveryServiceDbContext()) { point = dbContext.Points .Select(p => new PointDTO() { Id = p.Id, Name = p.Name }) .Where(p => p.Id.Equals(pointId)) .SingleOrDefault <PointDTO>(); } return(point); }
public async Task <IActionResult> PostPoint(long idMatch, [FromBody] PointDTO pointDto) { List <Error> errors = new List <Error>(); Account currentUser = await GetCurrentUserAsync(); var matchs = _context.Tournaments .SelectMany(t => t.Matches) .Where(t => t.Id == idMatch && t.Arbitre == currentUser) .Include(m => m.Score); errors = PointDTOValidator.Validate(pointDto, errors); if (matchs.Count() > 0 && errors.Count() <= 0) { Point point = pointDto.GetPoint(); Match match = matchs.Single(); int maxOrder; if (match.Score != null && match.Score.Count() > 0) { maxOrder = match.Score.Max(p => p.Order); } else { match.Score = new List <Point>(); maxOrder = 0; } point.Order = maxOrder + 1; match.Score.Add(point); _context.SaveChanges(); Score score = new CalculPointPingPong().Calcul(match.Score); return(Created("", score)); } else if (matchs.Count() <= 0) { errors.Add(new Error() { Code = "MatchUnknowOrUnAuhthorize", Description = "Le match n'as pas été trouver ou vous n'avez pas acces au match" }); return(BadRequest(errors)); } return(BadRequest(errors)); }
public void PutInvalidPointTest() { PointDTO mockedPoint = this.getMockedPoints().ElementAt(0); this.pointsAdminService.UpdatePoint(Arg.Any <PointDTO>()).Returns(mockedPoint); PointDTO point = new PointDTO() { Name = "A" }; IHttpActionResult actionResult = this.pointsController.Put(point); // assertions this.pointsAdminService.DidNotReceive().UpdatePoint(point); BadRequestErrorMessageResult badRequestMessage = actionResult as BadRequestErrorMessageResult; Assert.IsNotNull(badRequestMessage); Assert.AreEqual(badRequestMessage.Message, "Point Id must be greater than 0."); }
public PointDTO Save(PointDTO point) { Point pointEntity = typeMapper.Map <PointDTO, Point>(point); using (var context = new DeliveryServiceDbContext()) { if (pointEntity.Id == 0) { context.Entry(pointEntity).State = EntityState.Added; } else { context.Entry(pointEntity).State = EntityState.Modified; } context.SaveChanges(); } return(typeMapper.Map <Point, PointDTO>(pointEntity)); }
public IHttpActionResult Post([FromBody] PointDTO point) { if (point.Id > 0) { return(BadRequest("Point Id cannot be defined for new entity.")); } IHttpActionResult actionResult = BadRequest(); if (ModelState.IsValid) { PointDTO savedPoint = this.pointsAdminService.CreatePoint(point); actionResult = Ok <PointDTO>(savedPoint); } else { actionResult = BadRequest(ModelState); } return(actionResult); }
public static List <Error> Validate(PointDTO point, List <Error> errors) { bool isCorrectJoueur = false; foreach (EJoueurs joueur in Enum.GetValues(point.Joueur.GetType())) { if (joueur == point.Joueur) { isCorrectJoueur = true; } } if (!isCorrectJoueur) { errors.Add(new Error() { Code = "JoueurUnknow", Description = "Ce joueur n'esxiste pas dans l'enumeration" }); } return(errors); }
public void PostPointTest() { PointDTO mockedPoint = this.getMockedPoints().ElementAt(0); this.pointsAdminService.CreatePoint(Arg.Any <PointDTO>()).Returns(mockedPoint); PointDTO point = new PointDTO() { Name = "A" }; IHttpActionResult actionResult = this.pointsController.Post(point); PointDTO expectedResult = mockedPoint; // assertions this.pointsAdminService.Received().CreatePoint(point); OkNegotiatedContentResult <PointDTO> contentResult = actionResult as OkNegotiatedContentResult <PointDTO>; Assert.IsNotNull(contentResult); Assert.AreEqual(expectedResult, contentResult.Content); }