public async Task <JObject> UpdateRecieptTypes(UpdateRecieptTypes postUpdate)
        {
            try
            {
                //Get receipt types
                var distributor  = GetDistributorById(postUpdate.DistributorId);
                var recieptTypes = distributor.ReceiptTypesOffered;


                bool newReceiptfound = false;
                bool oldRecieptFound = false;

                if (recieptTypes != null)
                {
                    distributor.ReceiptTypesOffered.ForEach(delegate(ReceiptType recieptType)
                    {
                        if (postUpdate.NewReciept != null && postUpdate.NewReciept.RtypeAsString.Equals(recieptType.RtypeAsString))
                        {
                            newReceiptfound = true;
                        }
                        if (postUpdate.OldReciept != null && postUpdate.OldReciept.RtypeAsString.Equals(recieptType.RtypeAsString))
                        {
                            oldRecieptFound = true;
                        }
                    });
                }
                else
                {
                    recieptTypes = new List <ReceiptType>()
                    {
                    };
                }

                // ---------------------------

                if (!newReceiptfound && postUpdate.NewReciept != null)
                {
                    //add receipt to list
                    recieptTypes.Add(
                        new ReceiptType()
                    {
                        RType         = postUpdate.NewReciept.RType,
                        RtypeAsString = postUpdate.NewReciept.RtypeAsString
                    });
                }
                else if (oldRecieptFound && postUpdate.OldReciept != null)
                {
                    ReceiptType receiptToRemove = recieptTypes.Find(r => r.RtypeAsString == postUpdate.OldReciept.RtypeAsString);
                    //remove old receipt from list
                    recieptTypes.Remove(receiptToRemove);
                }

                else
                {
                    return
                        (JObject.FromObject(
                             new
                    {
                        status = "false",
                        result = false,
                        message = "Could not update Receipt Types."
                    }
                             ));
                }

                return(await UpdateDistributor(postUpdate.DistributorId, recieptTypes));
            }
            catch (Exception ex)
            {
                return
                    (JObject.FromObject(
                         new
                {
                    status = "Exception Thrown",
                    result = false,
                    message = ex.Message
                }
                         ));
            }
        }
 public Task <JObject> UpdateRecieptTypes(UpdateRecieptTypes postUpdate)
 {
     return(_distributorsServiceClient.UpdateRecieptTypes(postUpdate));
 }
Beispiel #3
0
 public async Task <JObject> UpdateRecieptTypes(UpdateRecieptTypes postUpdate)
 {
     return(await _composer.UpdateRecieptTypes(postUpdate));
 }