예제 #1
0
        public RedirectToRouteResult PostOrder(CustomerOrderHeaderDTO Order)
        {
            Order.Date_ = DateTime.Now;

            List <CustomerOrderDTO> list = new List <CustomerOrderDTO>();

            foreach (var item in Session["OrderBoxList"] as List <OrderBox> )
            {
                list.Add(new CustomerOrderDTO()
                {
                    Amount          = item.Amount,
                    Barcode         = item.Barcode,
                    Description     = item.Description,
                    ProductId       = item.ProductId,
                    GUID            = item.GUID,
                    Price           = Convert.ToDouble(item.Price),
                    CustomerOrderId = item.CustomerOrderId,
                    ProductName     = item.ProductName
                });
            }
            Order.CustomerOrder = list;
            Order.OrderPrice    = list.Sum(a => a.Price) * list.Sum(a => a.Amount);

            Repositories.CustomerOrderRepository.CustomerOrderPost(Order);
            ViewBag.message = "Siparişiniz Eklendi";
            return(RedirectToAction("GetAllorders"));
        }
        public static void CustomerOrderPut(CustomerOrderHeaderDTO customerOrder)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(APIURL);
                client.DefaultRequestHeaders.Accept.Clear();

                var serializedProduct = JsonConvert.SerializeObject(customerOrder);
                var content           = new StringContent(serializedProduct, Encoding.UTF8, "application/json");

                var Result = client.PutAsync(APIURL + "orders/", content);
            }
        }
        public static CustomerOrderHeaderDTO GetOrder(int id)
        {
            CustomerOrderHeaderDTO order = null;

            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(APIURL);
                client.DefaultRequestHeaders.Accept.Clear();

                var requestContent = client.GetAsync(APIURL + "orders/" + id).Result;
                if (requestContent.IsSuccessStatusCode)
                {
                    order = JsonConvert.DeserializeObject <CustomerOrderHeaderDTO>(requestContent.Content.ReadAsStringAsync().Result);
                }
            }
            return(order);
        }
예제 #4
0
        public HttpResponseMessage PutOrder(int id, CustomerOrderHeaderDTO customerOrderHeaderDTO)
        {
            HttpResponseMessage message = null;

            try
            {
                CustomerOrderRepository customerRepo = new CustomerOrderRepository();
                customerRepo.PostOrder(customerOrderHeaderDTO);

                message = Request.CreateResponse(HttpStatusCode.Accepted, "Ekleme İşlem Tamamlandı");

                customerRepo = null;
            }
            catch (Exception ex)
            {
                message = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message.ToString());
            }

            return(message);
        }
예제 #5
0
        public ActionResult Index()
        {
            Session["OrderBoxList"] = null;

            ViewBag.Customers = CustomerRepository.GetCustomerList();
            ViewBag.Products  = ProductRepository.GetProductList();
            ViewBag.message   = "";
            var OrderViewDataModel = new CustomerOrderHeaderDTO()
            {
                CustomerId = 1,
                OrderId    = 0,
                OrderRow   = new CustomerOrderDTO()
                {
                    //ProductId = 1,
                    Barcode = string.Empty,
                    Amount  = 1,
                    Price   = 0,
                    GUID    = string.Empty
                }
            };

            return(View(OrderViewDataModel));
        }
예제 #6
0
        public void PostOrder(CustomerOrderHeaderDTO customerOrderDTO)
        {
            CustomerOrderHeader Order = null;

            using (LcwDBEntities db = new LcwDBEntities())
            {
                var Data = (from d in db.CustomerOrderHeader
                            where d.OrderId == customerOrderDTO.OrderId
                            select d).FirstOrDefault();

                int OrderId = 0;

                if (Data != null)
                {
                    Data.OrderAdress = customerOrderDTO.OrderAdress;
                    Data.Date_       = customerOrderDTO.Date_;
                    Data.OrderPrice  = customerOrderDTO.OrderPrice;
                    Data.CustomerId  = customerOrderDTO.CustomerId;
                    OrderId          = customerOrderDTO.OrderId;
                    db.SaveChanges();
                }
                else
                {
                    Order = new CustomerOrderHeader()
                    {
                        CustomerId  = customerOrderDTO.CustomerId,
                        OrderAdress = customerOrderDTO.OrderAdress,
                        OrderPrice  = customerOrderDTO.OrderPrice,
                        Date_       = customerOrderDTO.Date_
                    };

                    db.CustomerOrderHeader.Add(Order);
                    db.SaveChanges();
                    OrderId = Order.OrderId;
                }



                var DBList = (from r in db.CustomerOrder
                              where r.OrderId == customerOrderDTO.OrderId
                              select r).ToList();

                var newRows = customerOrderDTO.CustomerOrder;


                foreach (var iRow in newRows)
                {
                    iRow.OrderId = OrderId;
                }

                // Güncelleme varmı ?
                foreach (var iNewRow in newRows)
                {
                    var data = DBList.Where(a => a.CustomerOrderId == iNewRow.CustomerOrderId).FirstOrDefault();
                    if (data != null)
                    {
                        data.Amount      = iNewRow.Amount;
                        data.ProductId   = iNewRow.ProductId;
                        data.Price       = iNewRow.Price;
                        data.Description = iNewRow.Description;
                        data.Barcode     = iNewRow.Barcode;
                        db.SaveChanges();
                    }
                }
                // Eklenen var mı ?
                foreach (var iNewRow in newRows)
                {
                    var data = DBList.Where(a => a.CustomerOrderId == iNewRow.CustomerOrderId).FirstOrDefault();
                    if (data == null)
                    {
                        db.CustomerOrder.Add(new CustomerOrder()
                        {
                            Amount      = iNewRow.Amount,
                            Price       = iNewRow.Price,
                            ProductId   = iNewRow.ProductId,
                            OrderId     = iNewRow.OrderId,
                            Description = iNewRow.Description,
                            Barcode     = iNewRow.Barcode,
                            Guid        = iNewRow.Guid
                        });
                        db.SaveChanges();
                    }
                }

                // Silinen var mı ?

                foreach (var iDBRow in DBList)
                {
                    var data = newRows.Where(a => a.CustomerOrderId == iDBRow.CustomerOrderId).FirstOrDefault();
                    if (data == null)
                    {
                        db.CustomerOrder.Remove(iDBRow);
                        db.SaveChanges();
                    }
                }
            }
        }