This is a migrated thread and some comments may be shown as answers.

Scaler value from int method on domainservice

0 Answers 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Waleed Seada
Top achievements
Rank 2
Waleed Seada asked on 15 Feb 2011, 07:47 PM
Dear all,
\
I have a question where I define a custom method on the domainservice with the invoke attribute.
I can call the method successfully from the client, but the problem is that the first call doesn't return the value, but in the second call it does .. funny isn't it ... what could be the reason.

This method is responsible of returning the maxID for an entity (id is generated by the application).
Method on the Domainservice:
[Invoke]
public int MaxCoinID()
{
    int coinid = GetIGL_coin().OrderBy(p => p.coin_id).ToList().Last().coin_id;
    return ++coinid;
}

The call to this from client through Dataservice class as follows:
public void GetNewCoinID()
{
    Context.MaxCoinID(MaxID_Loaded, null);
}
public void MaxID_Loaded(InvokeOperation<int>invokeOperation)
{
    LastID = invokeOperation.Value;
}

LastID is a property on the Dataservice class, which is being used in the save function at the same class as follows:

public bool SaveCoin(IGL_coin coin)
{
    GetNewCoinID();
    //GetNewCoinID();
    coin.coin_id = ++LastID;
    Context.IGL_coins.Add(coin);
    var ss = Context.SubmitChanges();
    if (ss.HasError)
    {
        LastError = ss.Error.Message;
        Context.RejectChanges();
        return false;
    }
    return true;
}


it is an irrelevant question to telerik controls, but I am seeking help from professionals.
Appreciate your help indeed.
Regards
Waleed

By the way:
I tried to use the VQCV but I don't know how to get the Max id from the view here is the code:
        public bool SaveCoin(IGL_coin coin)
        {
            var query = Context.GetIGL_coinQuery().OrderBy(p => p.coin_id);
            query.IncludeTotalCount = true;
  
            var view = new VirtualQueryableCollectionView() { LoadSize = 10, VirtualItemCount = 100 };
            view.ItemsLoading += (s, e) =>
                {
                    Context.Load<IGL_coin>(query).Completed += 
                    (sender, args) =>
                    {
                        var lo = (LoadOperation) sender;
                        if (lo.TotalEntityCount != -1) view.VirtualItemCount = lo.TotalEntityCount;
                        view.Load(e.StartIndex, lo.Entities);
                    };
                };
//LastID = ((IGL_coin)view.GetItemAt(view.TotalItemCount - 1)).coin_id;
}

The commented line gives converssion error !! 



No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Waleed Seada
Top achievements
Rank 2
Share this question
or