public HttpResponseMessage CommentPlace([ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey, CommentPlace comment)
        {
            var operationResult = this.PerformOperationAndHandleExceptions(() =>
            {
                var user = NationalPlacesDAL.Get<NationalPlaces.Models.User>("UsersInformation")
                    .FirstOrDefault(x => x.SessionKey == sessionKey);

                if (user == null)
                {
                    throw new InvalidOperationException("User or password is incorrect.");
                }

                double longitude = 0;
                double latitude = 0;
                DecryptCoordinateToken(comment.LocationToken, user.AuthCode, ref longitude, ref latitude);
                var avaiablePlaces = GetNearPlaces(longitude, latitude);
                if (avaiablePlaces == null || avaiablePlaces.Count() == 0)
                {
                    throw new InvalidOperationException("There are no places near by.");
                }

                var placeToComment = avaiablePlaces.Where(x => x.PlaceIndentifierNumber == comment.PlaceIndentifierNumber).FirstOrDefault();
                if (placeToComment == null)
                {
                    throw new InvalidOperationException("You cant comment this place. It is not near you.");
                }

                var newComment = new NationalPlaces.Models.Comment()
                {
                    UserNickName = user.NickName,
                    Text = comment.Content
                };

                placeToComment.Comments.Add(newComment);
                NationalPlacesDAL.SaveEntity(placeToComment, "PlaceInformation");

                return Request.CreateResponse(HttpStatusCode.OK);
            });

            return operationResult;
        }
示例#2
0
        public HttpResponseMessage CommentPlace([ValueProvider(typeof(HeaderValueProviderFactory <string>))] string sessionKey, CommentPlace comment)
        {
            var operationResult = this.PerformOperationAndHandleExceptions(() =>
            {
                var user = NationalPlacesDAL.Get <NationalPlaces.Models.User>("UsersInformation")
                           .FirstOrDefault(x => x.SessionKey == sessionKey);

                if (user == null)
                {
                    throw new InvalidOperationException("User or password is incorrect.");
                }

                double longitude = 0;
                double latitude  = 0;
                DecryptCoordinateToken(comment.LocationToken, user.AuthCode, ref longitude, ref latitude);
                var avaiablePlaces = GetNearPlaces(longitude, latitude);
                if (avaiablePlaces == null || avaiablePlaces.Count() == 0)
                {
                    throw new InvalidOperationException("There are no places near by.");
                }

                var placeToComment = avaiablePlaces.Where(x => x.PlaceIndentifierNumber == comment.PlaceIndentifierNumber).FirstOrDefault();
                if (placeToComment == null)
                {
                    throw new InvalidOperationException("You cant comment this place. It is not near you.");
                }

                var newComment = new NationalPlaces.Models.Comment()
                {
                    UserNickName = user.NickName,
                    Text         = comment.Content
                };

                placeToComment.Comments.Add(newComment);
                NationalPlacesDAL.SaveEntity(placeToComment, "PlaceInformation");

                return(Request.CreateResponse(HttpStatusCode.OK));
            });

            return(operationResult);
        }