Example #1
0
        private BaseResponse HandleGetMyTags(DynamicDictionary _parameters)
        {
            User         user;
            BaseResponse response;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                int page     = _parameters["page"];
                int pageSize = _parameters["pagesize"];

                HydrantWikiManager hwm = new HydrantWikiManager();

                List <Tag>         tags       = hwm.GetTagsForUser(user.Guid, page, pageSize);
                List <Objects.Tag> outputTags = new List <Objects.Tag>();

                foreach (Tag tag in tags)
                {
                    Objects.Tag outputTag = new Objects.Tag(tag);
                    outputTags.Add(outputTag);
                }

                int count = hwm.GetTagCount(user.Guid);
                int pages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(count) / Convert.ToDouble(pageSize)));

                response = new TagsResponse(outputTags, page, pageSize, pages, count);
            }
            else
            {
                LogUnauthorized(Request);
                response = new BaseResponse
                {
                    Success = false,
                    Error   = "Unauthorized",
                    Message = "Reauthenticate"
                };
            }

            return(response);
        }
Example #2
0
        private BaseResponse HandleTagPost(DynamicDictionary _parameters)
        {
            HydrantWikiManager hwManager = new HydrantWikiManager();

            var response = new TagPostResponse {
                Success = false
            };
            User user;

            if (AuthHelper.IsAuthorized(Request, out user))
            {
                try
                {
                    string json = Request.Body.ReadAsString();

                    Objects.Tag tag = JsonConvert.DeserializeObject <Objects.Tag>(json);

                    if (tag != null)
                    {
                        if (tag.Position != null)
                        {
                            if (tag.Position != null)
                            {
                                var dbTag = new HydrantWiki.Library.Objects.Tag
                                {
                                    Active               = true,
                                    DeviceDateTime       = tag.Position.DeviceDateTime,
                                    LastModifiedDateTime = DateTime.UtcNow,
                                    UserGuid             = user.Guid,
                                    VersionTimeStamp     = DateTime.UtcNow.ToString("u"),
                                    Position             = new GeoPoint(tag.Position.Longitude, tag.Position.Latitude),
                                    ImageGuid            = tag.ImageGuid,
                                    Status               = TagStatus.Pending
                                };

                                hwManager.Persist(dbTag);
                                hwManager.LogVerbose(user.Guid, "Tag Saved");

                                response.ImageUrl     = dbTag.GetUrl(false);
                                response.ThumbnailUrl = dbTag.GetUrl(true);

                                response.Success = true;
                                return(response);
                            }
                            else
                            {
                                //No position
                                hwManager.LogWarning(user.Guid, "No position");

                                response.Message = "No position";
                                return(response);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceFileHelper.Error("Failure to post tag");
                    hwManager.LogException(user.Guid, ex);
                }
            }
            else
            {
                LogUnauthorized(Request);
                response.Error   = "Unauthorized";
                response.Message = "Reauthenticate";
            }

            return(response);
        }