コード例 #1
0
    private string SaveVersionItem(string groupId, string versionNumber, SaveType saveType)
    {
        // todo : there is a hack there with the 2 seconds added to the current date time. Fix this.
        // The reason is that if two versions are created within one second of each other, then the
        // 'current' version will be the first one that was created. Usually the second one is the
        // latest/current one. This is a defect whereby we determine that the latest timestamped
        // version is the current one. There should be a flag on a version saying that it is the latest.
        VersionManager.CreateVersionItem(new VersionItem()
        {
            ItemId        = Item.Id,
            GroupId       = groupId,
            VersionNumber = versionNumber,
            DateCreated   = (saveType == SaveType.Publish) ? DateTime.Now.AddSeconds(2.0) : DateTime.Now,
            Comments      = ctrlEditComments.GetComments(),
            ModifiedBy    = Utilities.GetUserName(Page.User.Identity.Name),
            EditSeverity  = (trEditDetails.Visible == true) ? rblEditDetails.SelectedValue : rblEditDetails.Items[1].Value
        });

        string approverItemId = VersionManager.GetVersionByItemId(Item.Id).Id;

        //start the approval process by adding approvers.
        ApproverManager.AddApprover(new BusiBlocks.ApproverLayer.Approver()
        {
            UserId = ddlApprovers.SelectedValue, CategoryId = currentSelectedNode, ItemId = approverItemId
        });
        return(VersionManager.GetVersionByGroupId(groupId).Id);
    }
コード例 #2
0
    protected void RadGrid1ItemCommand(object sender, GridCommandEventArgs e)
    {
        ((IFeedback)Page.Master).HideFeedback();

        if (e.CommandName == "view")
        {
            GridDataItem item       = (GridDataItem)e.Item;
            var          lnkbtnView = (LinkButton)e.Item.FindControl("imgBtnView");
            AuditManager.Audit(Page.User.Identity.Name, item["Id"].Text, AuditRecord.AuditAction.Viewed);
            Navigation.Communication_NewsViewItem(lnkbtnView.CommandArgument.ToString(CultureInfo.InvariantCulture)).Redirect(this);
        }
        else if (e.CommandName == "editVersion")
        {
            //edit link to be be the VersionID
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            string      groupId       = string.Empty;
            if (versionByItem != null)
            {
                groupId = versionByItem.GroupId;
                string versionId = (VersionManager.GetVersionByGroupId(groupId)).Id;

                string checkedoutUser = VersionManager.GetCheckedOutUser(groupId);
                if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
                {
                    ((IFeedback)Page.Master).SetError(GetType(), "Unable to edit: News Item is checked out to " + checkedoutUser);
                }
                else
                {
                    //perform checkout by the user here
                    VersionManager.CheckOutVersion(versionId, Page.User.Identity.Name);
                    Navigation.Communication_NewsEditItem(versionId).Redirect(this);
                }
            }
            else //for existing announcements which dont have a version
            {
                //create a version out of the existing announcement

                string itemId        = e.CommandArgument.ToString();
                string VersionNumber = VersionManager.GetVersionNumber(VersionType.New, string.Empty);

                VersionManager.CreateVersionItem(new VersionItem()
                {
                    ItemId        = itemId,
                    GroupId       = itemId,
                    VersionNumber = VersionNumber,
                    DateCreated   = DateTime.Now,
                    Comments      = string.Empty,
                    ModifiedBy    = Utilities.GetUserName(Page.User.Identity.Name)
                });

                //get the version by itemId and then check out.
                string versionId = VersionManager.GetVersionByItemId(itemId).Id;


                VersionManager.CheckOutVersion(versionId, Utilities.GetUserName(Page.User.Identity.Name));

                Navigation.Communication_NewsEditItem(versionId).Redirect(this);
            }
        }
        else if (e.CommandName == "delete")
        {
            Item   itemToDelete         = NewsManager.GetItem(e.CommandArgument.ToString());
            string itemNameBeforeDelete = itemToDelete.Title;
            string groupID = VersionManager.GetVersionByItemId(itemToDelete.Id).GroupId;

            string checkedoutUser = VersionManager.GetCheckedOutUser(groupID);
            if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
            {
                ((IFeedback)Page.Master).SetError(GetType(), "Unable to delete: News Item is checked out to " + checkedoutUser);
            }
            else
            {
                string itemIdBeforeDelete = itemToDelete.Category.Id;
                NewsManager.DeleteItemByGroup(groupID);

                //Controls_TreeView tree = (Controls_TreeView)this.Parent.FindControl("tree1");
                //tree.PopulateTreeView<Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), false, false, string.Empty);
                //tree.RebindNode(itemIdBeforeDelete, false);

                ((IFeedback)Page.Master).ShowFeedback(BusiBlocksConstants.Blocks.Administration.ShortName, itemToDelete.GetType().Name, Feedback.Actions.Deleted, itemNameBeforeDelete);
            }
        }
        else if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair filterPair           = (Pair)e.CommandArgument;
            List <NewsGridItem> items = new List <NewsGridItem>();

            switch (filterPair.Second.ToString())
            {
            case "Category":
                TextBox tbPattern = (e.Item as GridFilteringItem)["Category"].Controls[0] as TextBox;
                FilterExpression = tbPattern.Text;
                BindWithFilter(items);
                RadGridManage.DataBind();
                if (!string.IsNullOrEmpty(FilterExpression))
                {
                    var foundNews  = NewsManager.GetCategoryByLikeName(FilterExpression.Split(',').First(), true);
                    int foundCount = foundNews.Count;
                    if (foundCount > 0)
                    {
                        //Controls_TreeView tree = (Controls_TreeView)this.Parent.FindControl("tree1");
                        //tree.PopulateTreeView<Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), false, false, string.Empty);
                        //string selectedNode = (foundNews.FirstOrDefault()).Id;
                        //tree.RebindNode(selectedNode, true);
                    }
                }
                break;

            default:
                break;
            }
        }
        else if (e.CommandName == "approveItem")
        {
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            string      groupId       = string.Empty;
            if (versionByItem != null)
            {
                groupId = versionByItem.GroupId;

                string checkedoutUser = VersionManager.GetCheckedOutUser(groupId);
                if ((!string.IsNullOrEmpty(checkedoutUser)) && (checkedoutUser != Page.User.Identity.Name))
                {
                    ((IFeedback)Page.Master).SetError(GetType(), "Unable to approve: News Item is checked out to " + checkedoutUser);
                }
                else
                {
                    string versionId = (VersionManager.GetVersionByGroupId(groupId)).Id;
                    Navigation.Communication_NewsViewItemApproval(versionId).Redirect(this);
                }
            }
            else
            {
                Navigation.Communication_NewsViewItemApproval(e.CommandArgument.ToString()).Redirect(this);
            }
        }
        else if (e.CommandName == "checkinItem")
        {
            VersionManager.CheckInVersion(e.CommandArgument.ToString());
            Navigation.Communication_News().Redirect(this);
        }
        else if (e.CommandName == "viewStatus")
        {
            // Navigate to the user view status page and pass the item id
            VersionItem versionByItem = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());
            if (versionByItem != null)
            {
                Navigation.Communication_UserViewStatus(versionByItem.ItemId, versionByItem.Id).Redirect(this);
            }
        }
        //else if (e.CommandName == "UsersViewed")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Viewed, totalUsers, publishedIds);

        //    foreach (User user in usersViewed)
        //        personsViewed.Add(user.Person.Id);

        //    Session["personList"] = personsViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersNotViewed")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsNotViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Viewed, totalUsers, publishedIds);

        //    foreach (User user in totalUsers)
        //        if (!usersViewed.Contains(user))
        //            personsNotViewed.Add(user.Person.Id);

        //    Session["personList"] = personsNotViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersAcked")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Acknowledged, totalUsers, publishedIds);

        //    foreach (User user in usersViewed)
        //        personsViewed.Add(user.Person.Id);

        //    Session["personList"] = personsViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
        //else if (e.CommandName == "UsersNotAcked")
        //{
        //    Item item = NewsManager.GetItem(e.CommandArgument.ToString());
        //    VersionItem version = VersionManager.GetVersionByItemId(e.CommandArgument.ToString());

        //    IList<User> totalUsers = GetTotalUsers(item.Category.Id);
        //    List<User> usersViewed = new List<BusiBlocks.Membership.User>();
        //    IList<string> personsNotViewed = new List<string>();

        //    //get the published id.
        //    List<string> publishedIds = new List<string>();
        //    publishedIds = GetRespectivePublishedVersions(version.GroupId, version.VersionNumber);

        //    usersViewed = GetViewUsers(AuditRecord.AuditAction.Acknowledged, totalUsers, publishedIds);

        //    foreach (User user in totalUsers)
        //        if (!usersViewed.Contains(user))
        //            personsNotViewed.Add(user.Person.Id);

        //    Session["personList"] = personsNotViewed;

        //    Navigation.Directory_Search().Redirect(this);
        //}
    }