public HttpResponseMessage Get(string id)
    {
        try
        {
            var item = BlogRollItem.GetBlogRollItem(Guid.Parse(id));
            if (item == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var result = new BlogRollRowItem
            {
                IsChecked   = false,
                Id          = item.Id,
                Title       = item.Title,
                Description = item.Description,
                BlogUrl     = item.BlogUrl.ToString(),
                FeedUrl     = item.FeedUrl.ToString(),
                Xfn         = item.Xfn
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        catch (UnauthorizedAccessException)
        {
            return(Request.CreateResponse(HttpStatusCode.Unauthorized));
        }
        catch (Exception)
        {
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
        }
    }
    public HttpResponseMessage ProcessChecked([FromBody] List <BlogRollRowItem> items)
    {
        try
        {
            if (items == null || items.Count == 0)
            {
                throw new HttpResponseException(HttpStatusCode.ExpectationFailed);
            }

            foreach (var item in items)
            {
                if (item.IsChecked)
                {
                    BlogRollItem br = BlogRollItem.GetBlogRollItem(item.Id);
                    br.Delete();
                    br.Save();
                }
            }
            Resort();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        catch (UnauthorizedAccessException)
        {
            return(Request.CreateResponse(HttpStatusCode.Unauthorized));
        }
        catch (Exception)
        {
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
        }
    }
    public HttpResponseMessage Update([FromBody] BlogRollRowItem item)
    {
        try
        {
            var br = BlogRollItem.GetBlogRollItem(item.Id);
            if (br == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            br.Title       = item.Title;
            br.Description = item.Description;
            br.BlogUrl     = new Uri(item.BlogUrl);
            br.FeedUrl     = new Uri(item.FeedUrl);
            br.Xfn         = item.Xfn.TrimEnd();
            br.Save();

            Resort();
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        catch (UnauthorizedAccessException)
        {
            return(Request.CreateResponse(HttpStatusCode.Unauthorized));
        }
        catch (Exception)
        {
            return(Request.CreateResponse(HttpStatusCode.InternalServerError));
        }
    }
Exemplo n.º 4
0
    protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // Don't want to handle Edit and Delete commands.
        if (!(e.CommandName.Equals("moveUp", StringComparison.OrdinalIgnoreCase) ||
              e.CommandName.Equals("moveDown", StringComparison.OrdinalIgnoreCase)))
        {
            return;
        }

        // If only one item in grid, there's nothing to adjust.
        if (grid.Rows.Count < 2)
        {
            return;
        }

        bool moveUp = e.CommandName.Equals("moveUp", StringComparison.OrdinalIgnoreCase);

        int rowIndex = Convert.ToInt32(e.CommandArgument);

        // If already at the top, can't move any higher.
        if (moveUp && rowIndex == 0)
        {
            return;
        }

        // If already at the bottom, can't move any lower.
        if (!moveUp && rowIndex == (grid.Rows.Count - 1))
        {
            return;
        }

        Guid         id       = (Guid)grid.DataKeys[rowIndex].Value;
        BlogRollItem brToMove = BlogRollItem.GetBlogRollItem(id);

        Guid         swapPositionWithId   = (Guid)grid.DataKeys[rowIndex + (moveUp ? -1 : 1)].Value;
        BlogRollItem brToSwapPositionWith = BlogRollItem.GetBlogRollItem(swapPositionWithId);

        if (brToMove != null && brToSwapPositionWith != null)
        {
            int newSortIndex = brToSwapPositionWith.SortIndex;
            brToSwapPositionWith.SortIndex = brToMove.SortIndex;
            brToMove.SortIndex             = newSortIndex;

            brToSwapPositionWith.Save();
            brToMove.Save();

            BlogRollItem.BlogRolls.Sort();
            Response.Redirect(Request.RawUrl);
        }
    }
Exemplo n.º 5
0
    public HttpResponseMessage Update([FromBody] BlogRollRowItem item)
    {
        var br = BlogRollItem.GetBlogRollItem(item.Id);

        if (br == null)
        {
            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }

        br.Title       = item.Title;
        br.Description = item.Description;
        br.BlogUrl     = new Uri(item.BlogUrl);
        br.FeedUrl     = new Uri(item.FeedUrl);
        br.Xfn         = item.Xfn.TrimEnd();
        br.Save();

        Resort();
        return(Request.CreateResponse(HttpStatusCode.OK));
    }
Exemplo n.º 6
0
    protected void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Guid         id = (Guid)grid.DataKeys[e.RowIndex].Value;
        BlogRollItem br = BlogRollItem.GetBlogRollItem(id);

        br.Delete();
        br.Save();

        int sortIndex = -1;

        // Re-sort remaining items starting from zero to eliminate any possible gaps.
        // Need to cast BlogRollItem.BlogRolls to an array to
        // prevent errors with modifying a collection while enumerating it.
        foreach (BlogRollItem brItem in BlogRollItem.BlogRolls.ToArray())
        {
            brItem.SortIndex = ++sortIndex;
            brItem.Save();
        }

        Response.Redirect(Request.RawUrl);
    }
Exemplo n.º 7
0
    public HttpResponseMessage Get(string id)
    {
        var item = BlogRollItem.GetBlogRollItem(Guid.Parse(id));

        if (item == null)
        {
            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }

        var result = new BlogRollRowItem
        {
            IsChecked   = false,
            Id          = item.Id,
            Title       = item.Title,
            Description = item.Description,
            BlogUrl     = item.BlogUrl.ToString(),
            FeedUrl     = item.FeedUrl.ToString(),
            Xfn         = item.Xfn
        };

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