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));
        }
    }
Пример #2
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);
    }