Exemple #1
0
        public static OrderOwner GetOrderOwner(FoodOrder foodOrder)
        {
            var orderOwner = new OrderOwner(foodOrder.OwnerName, foodOrder.Street, foodOrder.HouseNumber,
                                            foodOrder.ContactNumber, string.Empty);

            return(orderOwner);
        }
Exemple #2
0
 private void OwnerForm(HttpClient client, OrderOwner orderOwner)
 {
     var content = new FormUrlEncodedContent(new[]
     {
         new KeyValuePair <string, string>(nameof(orderOwner.name), orderOwner.name),
         new KeyValuePair <string, string>(nameof(orderOwner.city), orderOwner.city.ToString()),
         new KeyValuePair <string, string>(nameof(orderOwner.street), orderOwner.street),
         new KeyValuePair <string, string>(nameof(orderOwner.streetnumber), orderOwner.streetnumber.ToString()),
         new KeyValuePair <string, string>(nameof(orderOwner.house), orderOwner.house),
         new KeyValuePair <string, string>(nameof(orderOwner.phone), orderOwner.phone),
         new KeyValuePair <string, string>(nameof(orderOwner.radio_fm), orderOwner.radio_fm)
     });
     var responce     = client.GetAsync("http://www.andys.md/ru/pages/cart/step2/").Result;
     var postResponse = client.PostAsync("http://www.andys.md/pages/setcartadr/", content).Result;
 }
Exemple #3
0
        public void Order(OrderOwner orderOwner, IList <CartItem> dish)
        {
            if (orderOwner == null)
            {
                throw new ArgumentNullException($"{nameof(orderOwner)} is null");
            }
            if (dish == null)
            {
                throw new ArgumentNullException($"{nameof(dish)} is null");
            }
            var client = new HttpClient();

            using (client)
            {
                foreach (var cartItem in dish)
                {
                    AddToCart(client, cartItem);
                }
                OwnerForm(client, orderOwner);

                // this method will sent the order to Andys
                //var submitOrder = SubmitOrder(client);
            }
        }
Exemple #4
0
        public ActionResponse <OrderRequest> Save_Orders(OrderRequest model)
        {
            ActionResponse <OrderRequest> response = new ActionResponse <OrderRequest>()
            {
                Response     = model,
                ResponseType = ResponseType.Ok
            };

            using (MspDbContext _db = new MspDbContext())
            {
                using (DbContextTransaction transaction = _db.Database.BeginTransaction())
                {
                    try
                    {
                        if (_db.OrderOwner.Any(x => x.SiparisNo == model.OrderOwner.SiparisNo && x.RecId == 0 && x.Deleted == false))
                        {
                            response.Message      = "Aynı Sipariş No'dan vardır.";
                            response.ResponseType = ResponseType.Error;
                            return(response);
                        }


                        int OrderOwnerId = 0;
                        if (response.Response.OrderOwner.RecId == 0)
                        {
                            OrderOwner orderOwner = base.Map <OrderOwnerDTO, OrderOwner>(model.OrderOwner);
                            _db.OrderOwner.Add(orderOwner);
                            _db.SaveChanges();
                            OrderOwnerId = orderOwner.RecId;
                        }
                        else
                        {
                            var entity = _db.OrderOwner.FirstOrDefault(x => x.RecId == response.Response.OrderOwner.RecId);
                            if (entity != null)
                            {
                                _db.Entry(entity).CurrentValues.SetValues(model.OrderOwner);
                                _db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                            }
                        }


                        foreach (var item in model.OrderTrans)
                        {
                            if (item.RecId == 0)
                            {
                                item.OwnerId = OrderOwnerId;
                                _db.OrderTrans.Add(base.Map <OrderTransDTO, OrderTrans>(item));
                                //var product = _db.products.FirstOrDefault(x => x.PID == item.ProductId);
                                //if (product != null)
                                //{
                                //    Products updatePro = new Products();
                                //    updatePro = product;
                                //    updatePro.PTotal = updatePro.PTotal - item.ProductQuantity;
                                //    _db.Entry(product).CurrentValues.SetValues(updatePro);
                                //    _db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                                //}
                            }
                            else
                            {
                                var entity = _db.OrderTrans.FirstOrDefault(x => x.RecId == item.RecId);
                                if (entity != null)
                                {
                                    _db.Entry(entity).CurrentValues.SetValues(item);
                                    _db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                                }
                            }
                        }
                        _db.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        response.Message      = e.ToString();
                        response.ResponseType = ResponseType.Error;
                    }
                }
            }
            return(response);
        }