Exemple #1
0
        //Delete Order

        public Boolean DeleteOrder(OrderViewModel ord)
        {
            using (Cobra db = new Cobra())
            {
                var model2 = db.OrderDetails.SingleOrDefault(x => x.Id == ord.productDetailsId);

                model2.OrderId         = ord.Id;
                model2.ProductId       = ord.ProductId;
                db.Entry(model2).State = System.Data.Entity.EntityState.Detached;
                db.OrderDetails.Attach(model2);
                db.OrderDetails.Remove(model2);
                db.SaveChanges();

                try
                {
                    var model = db.OrderHeaders.SingleOrDefault(x => x.OrderId == ord.Id);
                    model.OrderDate       = ord.OrderDate;
                    model.PersonId        = ord.PersonId;
                    db.Entry(model).State = System.Data.Entity.EntityState.Detached;
                    db.OrderHeaders.Attach(model);
                    db.OrderHeaders.Remove(model);
                    db.SaveChanges();
                }catch (Exception e) {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        //Add Order
        public Boolean AddOrderDetails(OrderViewModel ord)
        {
            using (var db = new Cobra()){
                try
                {
                    var orderHeader = new OrderHeader
                    {
                        OrderDate = ord.OrderDate,
                        PersonId  = ord.PersonId,
                    };
                    db.OrderHeaders.Add(orderHeader);
                    db.SaveChanges();

                    var orderDetail = new OrderDetail
                    {
                        OrderId   = orderHeader.OrderId,
                        ProductId = ord.ProductId
                    };

                    db.OrderDetails.Add(orderDetail);
                    db.SaveChanges();
                }
                catch (Exception) {
                    return(false);
                }
            }

            return(true);
        }
        //Update People
        public Boolean UpdatePerson(PersonViewModel person)
        {
            var people = new Person
            {
                Id       = person.Id,
                Name     = person.Name,
                Address1 = person.Address1,
                Address2 = person.Address2,
                City     = person.City
            };


            if (people != null)
            {
                using (Cobra Obj = new Cobra())
                {
                    var emp    = Obj.Entry(people);
                    var result = Obj.People.Where(x => x.Id == person.Id).FirstOrDefault();
                    result.Name     = person.Name;
                    result.Address1 = person.Address1;
                    result.Address2 = person.Address2;
                    result.City     = person.City;
                    Obj.SaveChanges();
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
        //Add people
        public Boolean InsertPeople(PersonViewModel person)
        {
            var people = new Person {
                Name     = person.Name,
                Address1 = person.Address1,
                Address2 = person.Address2,
                City     = person.City
            };

            if (people != null)
            {
                _context.People.Add(people);
                _context.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
        //Update Order
        public Boolean upOrder(OrderViewModel ord)
        {
            using (Cobra Obj = new Cobra())
            {
                var model = Obj.OrderHeaders.SingleOrDefault(x => x.OrderId == ord.OrderId);
                model.OrderDate = ord.OrderDate;
                model.PersonId  = ord.PersonId;

                Obj.Entry(model).State = EntityState.Modified;

                Obj.SaveChanges();

                var model2 = Obj.OrderDetails.SingleOrDefault(x => x.Id == ord.Id);
                model2.OrderId          = ord.OrderId;
                model2.ProductId        = ord.ProductId;
                Obj.Entry(model2).State = EntityState.Modified;
                Obj.SaveChanges();

                return(true);
            }
        }