private void _OnSignalREvent(string aEventName, object aEventData)
        {
            switch (aEventName)
            {
            case "ProductListCreated":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = new ProductListDTO()
                    {
                        Id = (int)lEventData["Id"],
                        Name = (string)lEventData["Name"] 
                    };
                    lock (this.ProductLists)
                        mProductLists.Add(lList);

                    _NotifyPropertyChanged("ProductLists");
                }
                break;
            case "ProductListDeleted":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["Id"]);
                    if (lList != null)
                    {
                        lock (this.ProductLists)
                            mProductLists.Remove(lList);

                        _NotifyPropertyChanged("ProductLists");
                    }
                }
                break;
            case "ProductEntryCreated":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = new ProductEntryDTO()
                        {
                            Id = (int)lEventData["Id"],
                            ProductName = (string)lEventData["Name"],
                            Amount = (int)lEventData["Amount"],
                            Comments = (string)lEventData["Comments"],
                            OwnerList = lList
                        };
                        lEntry.PropertyChanged += _OnProductEntryPropertyChanged;
                        lock (lList.mProductEntries)
                            lList.mProductEntries.Add(lEntry);

                        lList._NotifyPropertyChanged("ProductEntries");
                    }
                }
                break;
            case "ProductEntryEdited":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = lList.ProductEntries.FirstOrDefault(aEntry => aEntry.Id == (int)lEventData["Id"]);
                        if (lEntry != null)
                        {
                            lEntry.Amount = (int)lEventData["Amount"];
                            lEntry.Comments = (string)lEventData["Comments"];
                        }
                    }
                }
                break;
            case "ProductEntryDeleted":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = lList.ProductEntries.FirstOrDefault(aEntry => aEntry.Id == (int)lEventData["Id"]);
                        if (lEntry != null)
                        {
                            lock (lList.mProductEntries)
                                lList.mProductEntries.Remove(lEntry);

                            lList._NotifyPropertyChanged("ProductEntries");
                        }
                    }
                }
                break;
            }
        }
 private async Task _DeleteProductEntry(ProductListDTO aProductList, ProductEntryDTO aProductEntry)
 {
     string lErrorMsg = null;
     try
     {
         await APIClient.DeleteProductEntry(aProductList, aProductEntry);
     }
     catch (Exception ex)
     {
         //In very high concurrent scenarios race conditions may ocurr, that lead the application to delete an already (just) deleted product entry
         if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.NotFound).ToString()))
         {
             //The given product entry was not found (probably already deleted in a race condition) Nothing is done
         }
         else if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.Forbidden).ToString()))
             lErrorMsg = "The server rejected the connection. Please update your client to the last version";
         else
             lErrorMsg = "Error communicating with server";
     }
     if (lErrorMsg != null)
         await _ShowMessageBox_Ok(lErrorMsg);
 }
 public async Task DeleteProductEntry(ProductListDTO aList, ProductEntryDTO aProductEntry)
 {
     using (this.SetBusy())
     {
         var lResponse = await mJSONRequester.Delete(this.ServerURL, string.Format(APIConstants.URL_DELETE_PRODUCT_ENTRY, aList.Id, aProductEntry.Id), mRequestHeaders);
         lResponse.EnsureSuccessStatusCode();
     }
 }
 private async Task _DeleteProductEntry(ProductListDTO aProductList, ProductEntryDTO aProductEntry)
 {
     try
     {
         await APIClient.DeleteProductEntry(aProductList, aProductEntry);
     }
     catch (Exception ex)
     {
         //In very high concurrent scenarios race conditions may ocurr, that lead the application to delete an already (just) deleted product entry
         if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.NotFound).ToString()))
         {
             //The given product entry was not found (probably already deleted in a race condition) Nothing is done
         }
         else if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.Forbidden).ToString()))
             MessageBox.Show(this, "The server rejected the connection. Please update your client to the last version", "Forbidden", MessageBoxButton.OK, MessageBoxImage.Stop);
         else
             MessageBox.Show(this, "Error communicating with server", "Network error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }