Exemplo n.º 1
0
        public override Elements.IElement <Data.Entities.Person> Save()
        {
            if (_resource.Id == Guid.Empty || _resource.Id == null)
            {
                _resource.Id = Guid.NewGuid();
            }

            foreach (var address in _resource.Addresses)
            {
                if (address.PersonId == Guid.Empty || address.PersonId == null)
                {
                    address.PersonId = Guid.NewGuid();
                }
            }

            lock ( _cust_writeLock ) {
                using (var context = new Data.PizzaBoxDbContext()) {
                    if (context.People.Find(_resource.Id) == null)
                    {
                        context.Entry(_resource);
                        context.Attach <Data.Entities.Person> (_resource);
                        context.Add <Data.Entities.Person> (_resource);
                    }

                    context.SaveChanges();
                }
            }

            return(new Customer(_resource));
        }
Exemplo n.º 2
0
        public override Elements.IElement <Data.Entities.Address> Save()
        {
            if (_resource.Id == Guid.Empty || _resource.Id == null)
            {
                _resource.Id = Guid.NewGuid();
            }

            lock ( _addr_writeLock ) {
                using (var context = new Data.PizzaBoxDbContext()) {
                    if (context.Addresses.Find(_resource.Id) == null)
                    {
                        context.Entry(_resource);
                        context.Attach(_resource);
                        context.Add <Data.Entities.Address> (_resource);
                    }

                    context.SaveChanges();
                }
            }

            return(new Address(_resource));
        }
Exemplo n.º 3
0
        public override Elements.IElement <Data.Entities.Outlet> Save()
        {
            if (_resource.Id == Guid.Empty || _resource.Id == null)
            {
                _resource.Id = Guid.NewGuid();
            }

            foreach (var address in _resource.Addresses)
            {
                if (address.Id == Guid.Empty || address.Id == null)
                {
                    address.Id = Guid.NewGuid();
                }
            }

            foreach (var employee in _resource.Employees)
            {
                if (employee.Id == Guid.Empty || employee.Id == null)
                {
                    employee.Id = Guid.NewGuid();
                }
            }

            foreach (var feature in _resource.Features)
            {
                if (feature.Id == Guid.Empty || feature.Id == null)
                {
                    feature.Id = Guid.NewGuid();
                }
            }

            foreach (var item in _resource.Items)
            {
                if (item.Id == Guid.Empty || item.Id == null)
                {
                    item.Id = Guid.NewGuid();
                }
            }

            foreach (var order in _resource.Orders)
            {
                if (order.Id == Guid.Empty || order.Id == null)
                {
                    order.Id = Guid.NewGuid();
                }
            }

            lock ( _biz_writeLock ) {
                using (var context = new Data.PizzaBoxDbContext()) {
                    if (context.Outlets.Find(_resource.Id) == null)
                    {
                        context.Entry(_resource);
                        context.Attach(_resource);
                        context.Add <Data.Entities.Outlet> (_resource);
                    }

                    context.SaveChanges();
                }
            }

            return(new Business(_resource));
        }