//^this needs to update the tab count

        private bool copyRequestItems(CswNbtRequestDataModel.CswRequestReturn.Ret Request, applyCopyLogic CopyLogic)
        {
            bool Succeeded = false;

            if (Request.RequestItems.Any())
            {
                //This is just a long way of saying "grab all MaterialDispense RequestItems in the current Request"
                //maybe don't use Linq to make it more readable? (unless we find a significant difference in performance)
                foreach (CswNbtObjClassRequestItem NewRequestItem in
                         from Item
                         in Request.RequestItems
                         select _CswNbtResources.Nodes[Item.NodePk]
                         into PropertySetRequest
                         where null != (CswNbtObjClassRequestItem)PropertySetRequest &&
                         (((CswNbtObjClassRequestItem)PropertySetRequest).Type.Value == CswNbtObjClassRequestItem.Types.MaterialBulk ||
                          ((CswNbtObjClassRequestItem)PropertySetRequest).Type.Value == CswNbtObjClassRequestItem.Types.MaterialSize ||
                          ((CswNbtObjClassRequestItem)PropertySetRequest).Type.Value == CswNbtObjClassRequestItem.Types.EnterprisePart)
                         select(CswNbtObjClassRequestItem) PropertySetRequest
                         into MaterialDispense
                         where null != MaterialDispense
                         //This is really sneaky - it's copying all of the MaterialDispense requests
                         //and throwing them into the collection we're selecting
                         select MaterialDispense.copyNode()
                         into NewPropSetRequest
                         select NewPropSetRequest)
                {
                    CopyLogic(NewRequestItem);

                    NewRequestItem.postChanges(ForceUpdate: false);

                    Succeeded = true;
                }
            }
            return(Succeeded);
        }
Ejemplo n.º 2
0
        public CswNbtRequestDataModel.CswRequestReturn copyRecurring(CswNbtRequestDataModel.CswRequestReturn.Ret Request)
        {
            //delegate has to be static because you can't create an instance yet: you don't have resources until the delegate is actually called
            CswNbtRequestDataModel.CswRequestReturn Ret = new CswNbtRequestDataModel.CswRequestReturn();
            var InitDriverType = new CswWebSvcDriver <CswNbtRequestDataModel.CswRequestReturn, CswNbtRequestDataModel.CswRequestReturn.Ret>(
                CswWebSvcResourceInitializer: new CswWebSvcResourceInitializerNbt(_Context, null),
                ReturnObj: Ret,
                WebSvcMethodPtr: CswNbtWebServiceRequesting.copyRecurring,
                ParamObj: Request
                );

            InitDriverType.run();
            return(Ret);
        }
        /// <summary>
        /// WCF method to copy a favorite to the current cart
        /// </summary>
        public static void copyFavorite(ICswResources CswResources, CswNbtRequestDataModel.CswRequestReturn Ret, CswNbtRequestDataModel.CswRequestReturn.Ret Request)
        {
            CswNbtResources NbtResources = _validate(CswResources);
            bool            Succeeded    = false;

            //...I have no idea what the difference is between Request.RequestId and Request.CswRequestId
            //I think they both refer to the current cart,
            //but then how are we differentiating between the current Request and the Favorite Request?
            if (CswTools.IsPrimaryKey(Request.CswRequestId) && Request.RequestItems.Any())
            {
                CswNbtObjClassRequest RequestNode = NbtResources.Nodes[Request.CswRequestId];
                if (null != RequestNode)
                {
                    CswNbtWebServiceRequesting ws         = new CswNbtWebServiceRequesting(NbtResources);
                    applyCopyLogic             SetRequest = (Item) =>
                    {
                        Item.Status.Value          = CswNbtObjClassRequestItem.Statuses.Pending;
                        Item.Request.RelatedNodeId = RequestNode.NodeId;
                    };
                    Succeeded = ws.copyRequestItems(Request, SetRequest);
                }
            }
            Ret.Data.Succeeded = Succeeded;
        }
        /// <summary>
        /// WCF method to copy request items to recurring
        /// </summary>
        public static void copyRecurring(ICswResources CswResources, CswNbtRequestDataModel.CswRequestReturn Ret, CswNbtRequestDataModel.CswRequestReturn.Ret Request)
        {
            CswNbtResources NbtResources = _validate(CswResources);
            bool            Succeeded    = false;

            if (Request.RequestItems.Any())
            {
                CswNbtWebServiceRequesting ws  = new CswNbtWebServiceRequesting(NbtResources);
                CswNbtActRequesting        act = new CswNbtActRequesting(NbtResources);
                //So here we're getting the "Recurring" Request and copying the request items from the current request into there
                CswNbtObjClassRequest RequestNode = act.getRecurringRequestNode();
                applyCopyLogic        SetRequest  = (Item) =>
                {
                    Item.Request.RelatedNodeId = RequestNode.NodeId;
                    Item.IsRecurring.Checked   = CswEnumTristate.True;
                };
                Succeeded = ws.copyRequestItems(Request, SetRequest);
            }
            Ret.Data.Succeeded = Succeeded;
        }
        /// <summary>
        /// WCF method to create a favorite
        /// </summary>
        public static void createFavorite(ICswResources CswResources, CswNbtRequestDataModel.CswRequestReturn Ret, CswNbtRequestDataModel.CswRequestReturn.Ret Request)
        {
            CswNbtResources NbtResources = _validate(CswResources);
            bool            Succeeded    = false;

            //This webservice is being called in the webclient twice - once to create the temp, and again to save the changes
            //this is really awkward - all this webservice should really do is return the Nodetypeid needed to do a traditional add
            //...oh, but wait, we need to make sure Favorite is checked in this case (and ONLY in this case) - *sigh*
            if (null != Request && false == string.IsNullOrEmpty(Request.RequestId))
            {
                CswNbtObjClassRequest Favorite = NbtResources.Nodes[Request.RequestId];
                if (null != Favorite)
                {
                    Succeeded = true;
                    Favorite.PromoteTempToReal();
                }
            }
            else
            {
                CswNbtMetaDataObjectClass RequestOc = NbtResources.MetaData.getObjectClass(CswEnumNbtObjectClass.RequestClass);
                CswNbtMetaDataNodeType    RequestNt = RequestOc.getLatestVersionNodeTypes().FirstOrDefault();
                if (null != RequestNt)
                {
                    CswNbtObjClassRequest Favorite = NbtResources.Nodes.makeNodeFromNodeTypeId(RequestNt.NodeTypeId, IsTemp: true);
                    if (null != Favorite)
                    {
                        Favorite.IsFavorite.Checked = CswEnumTristate.True;
                        Favorite.Name.Text          = string.Empty;
                        Favorite.postChanges(ForceUpdate: false);
                        Succeeded = true;
                        CswPropIdAttr NameIdAttr = new CswPropIdAttr(Favorite.Node, Favorite.Name.NodeTypeProp);
                        Ret.Data.CswRequestId   = Favorite.NodeId;
                        Ret.Data.CswRequestName = NameIdAttr;
                    }
                }
            }
            Ret.Data.Succeeded = Succeeded;
        }