public async Task<Point> CreateAsync(string description) { // Error if point description is invalid value or already in use await ValidatePointInvalidAsync(description); await _pointRepository.AddAsync(new Point { Description = description }); _cacheManager.RemoveBulkWithExpression(CacheKeys.Route); return (await _pointRepository.GetAsync()).FirstOrDefault(x => x.Description.Equals(description)); }
public async Task <SavePointResponse> SaveAsync(Point point) { try { await _pointRepository.AddAsync(point); await _unitOfWork.CompleteAsync(); return(new SavePointResponse(point)); } catch (Exception ex) { // Do some logging stuff return(new SavePointResponse($"An error occurred when saving the point: {ex.Message}")); } }
public async Task <IDataResult <long> > CreatePostAsync(PostModel post) { var user = _userRepository.FirstOrDefault(u => u.Id == post.UserId); PointEntity point = await _pointRepository.FirstOrDefaultWhereIncludeAsync(p => p.Id == post.Marker.Id, p => p.Posts); if (point is null) { point = new PointEntity { Coordinate = new Coordinate { Latitude = post.Marker.Latitude, Longitude = post.Marker.Longitude } }; await _pointRepository.AddAsync(point); point.User = user; } var newPost = new PostEntity { Message = post.Message, Recommended = post.Recommended, PostDate = DateTime.UtcNow, Location = post.Location }; await _postRepository.AddAsync(newPost); newPost.Point = point; newPost.User = user; _tagRepository.CreateTags(post.Tags, user.Id); await _unitOfWork.SaveChangesAsync(); var postTags = _tagRepository.GetTagsByNames(post.Tags); await _postTagRepository.AddRangeAsync(postTags.Select(t => new PostTagEntity { PostId = newPost.Id, TagId = t.Id })); await _unitOfWork.SaveChangesAsync(); return(DataResult <long> .Success(newPost.Id)); }
public async Task <ActionResult> Post() { var p = Point.CreatePoint(); try { p.IsWater = await onWaterApi.IsOnWaterAsync(p); } catch (ApiException e) { logger.LogWarning(e.Message); //it seems that we reached our 15/minute api calls limit return(StatusCode(422, e.Message)); //422 - Unprocessable failure } await repository.AddAsync(p); return(new JsonResult(new PointViewModel { IsWater = p.IsWater, Longitude = p.Longitude, Latitude = p.Latitude })); }