// PUT api/<controller>/5
        public object Put(string userid, Myorder u)
        {
            try
            {
                if (userid == u.Userid)
                {
                    smt.Entry(u).State = System.Data.Entity.EntityState.Modified;
                    smt.SaveChanges();
                    return(new Response
                    {
                        Status = "Updated",
                    });
                }
                else
                {
                    return(new Response
                    {
                        Status = "opps",
                    });
                }
            }
            catch (Exception e)
            {
                Console.Write("error");
            }

            return(new Response
            {
                Status = "Error",
            });
        }
Пример #2
0
 public static decimal GetAmount(this Myorder order, BankSyncConverter converter)
 {
     if (order.payment.amount?.amount != null)
     {
         return(converter.ToDecimal(order.payment.amount.amount));
     }
     else
     {
         return(converter.ToDecimal(order.totalCost.amount));
     }
 }
Пример #3
0
        private BankEntry PrepareNewBankEntryForOffer(Myorder allegroEntry, int offerIndex, BankEntry entry,
                                                      AllegroDataContainer container)
        {
            Offer     offer    = allegroEntry.offers[offerIndex];
            BankEntry newEntry = BankEntry.Clone(entry);

            newEntry.Amount = this.converter.ToDecimal(offer.offerPrice.amount);

            newEntry.Note = $"ZWROT: {offer.title} (Ilość sztuk: {offer.quantity}, Oferta {offer.id}, Pozycja {offerIndex + 1}/{allegroEntry.offers.Length})";

            newEntry.Payer        = "allegro.pl - " + allegroEntry.seller.login;
            newEntry.Recipient    = container.ServiceUserName;
            newEntry.FullDetails += $"\r\nPłatność Allegro: {allegroEntry.payment.id}.\r\n URL: {offer.friendlyUrl}";
            return(newEntry);
        }
        // DELETE api/<controller>/5
        public Response Delete(int Oid)
        {
            Myorder u = smt.Myorders.Find(Oid);

            if (u != null)
            {
                smt.Myorders.Remove(u);
                smt.SaveChanges();
                return(new Response
                {
                    Status = "delete"
                });
            }

            return(new Response
            {
                Status = "Error"
            });
        }
 // POST api/<controller>
 public object Post(Myorder u)
 {
     try
     {
         smt.Myorders.Add(u);
         smt.SaveChanges();
         return(new Response
         {
             Status = "added",
         });
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         return(new Response
         {
             Status = "Error",
         });
     }
 }
Пример #6
0
        private decimal CalculateTotalAmount(List <Myorder> relevantOrders)
        {
            Myorder firstOrder = relevantOrders.First();
            Payment payment    = firstOrder.payment;

            if (relevantOrders.All(x => x.payment.id == payment.id))
            {
                return(this.converter.ToDecimal(payment.amount.amount) * -1);
            }
            else
            {
                IEnumerable <IGrouping <string, Myorder> > groupings = relevantOrders.GroupBy(x => x.payment.id);
                decimal totalAmount = 0;
                foreach (IGrouping <string, Myorder> grouping in groupings)
                {
                    Payment groupPayment = grouping.First().payment;
                    decimal partial      = this.converter.ToDecimal(groupPayment.amount.amount);
                    totalAmount += partial;
                }

                return(totalAmount * -1);
            }
        }
Пример #7
0
        private void HandlePartialRefunds(BankEntry entry, List <BankEntry> updatedEntries, Myorder order,
                                          AllegroDataContainer container)
        {
            List <Offer> offersWithProperPrice =
                order.offers.Where(x => this.converter.ToDecimal(x.offerPrice.amount) == entry.Amount).ToList();

            if (offersWithProperPrice.Any())
            {
                if (offersWithProperPrice.Count == 1)
                {
                    Offer     offer    = offersWithProperPrice.First();
                    BankEntry newEntry = BankEntry.Clone(entry);

                    newEntry.Note = $"ZWROT: {offer.title} (Ilość sztuk: {offer.quantity}, Oferta {offer.id})";

                    newEntry.Payer        = "allegro.pl - " + order.seller.login;
                    newEntry.Recipient    = container.ServiceUserName;
                    newEntry.FullDetails += $"\r\nPłatność Allegro: {order.payment.id}.\r\n URL: {offer.friendlyUrl}";
                    updatedEntries.Add(newEntry);
                }
                else
                {
                    BankEntry newEntry = BankEntry.Clone(entry);

                    newEntry.Note = "ZWROT pasujący do jednej z ofert: " +
                                    string.Join("\r\n", offersWithProperPrice.Select(x => x.title));

                    newEntry.Payer        = "allegro.pl - " + order.seller.login;
                    newEntry.Recipient    = container.ServiceUserName;
                    newEntry.FullDetails += $"\r\nPłatność Allegro: {order.payment.id}.\r\n{newEntry.Note}";
                    updatedEntries.Add(newEntry);
                }
            }
        }
Пример #8
0
        private void AddDeliveryCost(BankEntry entry, List <BankEntry> updatedEntries, Myorder allegroEntry,
                                     AllegroDataContainer container)
        {
            if (allegroEntry.delivery.cost.amount != "0.00")
            {
                //lets add a delivery cost as a separate entry, but assign it a category etc. of the most expensive item
                Offer mostExpensive =
                    allegroEntry.offers.OrderByDescending(x => this.converter.ToDecimal(x.offerPrice.amount)).First();

                BankEntry deliveryEntry = BankEntry.Clone(entry);
                deliveryEntry.Amount = this.converter.ToDecimal(allegroEntry.delivery.cost.amount) * -1;
                deliveryEntry.Note   =
                    $"DOSTAWA: {mostExpensive.title} (Oferta {mostExpensive.id}, Suma zamówień: {allegroEntry.offers.Length})";
                deliveryEntry.Recipient = "allegro.pl - " + allegroEntry.seller.login;
                deliveryEntry.Tags.Add("dostawa");
                if (string.IsNullOrEmpty(deliveryEntry.Payer))
                {
                    deliveryEntry.Payer = container.ServiceUserName;
                }

                deliveryEntry.FullDetails +=
                    $"\r\nPłatność Allegro: {allegroEntry.payment.id}.\r\n URL: {mostExpensive.friendlyUrl}";
                updatedEntries.Add(deliveryEntry);
            }
        }