public void PostCustomer(CustomerDTO customerDTO)
        {
            using (LcwDBEntities db = new LcwDBEntities())
            {
                var Data = (from d in db.Customer
                            where d.CustomerId == customerDTO.CustomerId
                            select d).FirstOrDefault();

                if (Data != null)
                {
                    Data.CustomerAdress = customerDTO.CustomerAdress;
                    Data.CustomerName   = customerDTO.CustomerName;
                }
                else
                {
                    db.Customer.Add(new Customer()
                    {
                        CustomerAdress = customerDTO.CustomerAdress,
                        CustomerName   = customerDTO.CustomerName
                    });
                }

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void PostProduct(ProductDTO productDTO)
        {
            using (LcwDBEntities db = new LcwDBEntities())
            {
                var Data = (from d in db.Product
                            where d.ProductId == productDTO.ProductId
                            select d).FirstOrDefault();

                if (Data != null)
                {
                    Data.Barcode     = productDTO.Barcode;
                    Data.Description = productDTO.Description;
                    Data.Quantity    = productDTO.Quantity;
                    Data.Price       = productDTO.Price;
                }
                else
                {
                    db.Product.Add(new Product()
                    {
                        Barcode     = productDTO.Barcode,
                        Description = productDTO.Description,
                        Price       = productDTO.Price,
                        Quantity    = productDTO.Quantity
                    });
                }

                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public void DeleteOrder(int OrderId)
        {
            using (LcwDBEntities db = new LcwDBEntities())
            {
                var Rows = db.CustomerOrder.Where(a => a.OrderId == OrderId).ToList();
                db.CustomerOrder.RemoveRange(Rows);

                db.SaveChanges();

                var data = db.CustomerOrderHeader.Where(a => a.OrderId == OrderId).FirstOrDefault();
                if (data != null)
                {
                    db.CustomerOrderHeader.Remove(data);
                    db.SaveChanges();
                }
            }
        }
 public void DeleteCustomer(int id)
 {
     using (LcwDBEntities db = new LcwDBEntities())
     {
         var data = db.Customer.Where(a => a.CustomerId == id).FirstOrDefault();
         if (data != null)
         {
             db.Customer.Remove(data);
             db.SaveChanges();
         }
     }
 }
Esempio n. 5
0
 public void DeleteProduct(int id)
 {
     using (LcwDBEntities db = new LcwDBEntities())
     {
         var data = db.Product.Where(a => a.ProductId == id).FirstOrDefault();
         if (data != null)
         {
             db.Product.Remove(data);
             db.SaveChanges();
         }
     }
 }
Esempio n. 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();
                    }
                }
            }
        }