public void AddReview(Restaurant rest, Review rev)
        {
            Restaurant checkID = _repoContext.Restaurants.Find(rest.ID);

            rest.Reviews.Add(rev);
            _repoContext.Entry(checkID).CurrentValues.SetValues(rest);
            _repoContext.SaveChanges();
        }
        public void DeleteRestaurant(Restaurant rest)
        {
            Restaurant checkID = _repoContext.Restaurants.Find(rest.ID);

            foreach (var item in rest.Reviews.ToList())
            {
                rest.Reviews.Remove(item);
                _repoContext.Entry(rest).CurrentValues.SetValues(rest);
                _repoContext.SaveChanges();
            }
            _repoContext.Restaurants.Remove(rest);
            _repoContext.SaveChanges();
        }
        public void LoadCredential(Object entity)
        {
            Account account;

            if (entity == null)
            {
                return;
            }

            // if has an account ...
            if (typeof(IHaveAccount).IsAssignableFrom(entity.GetType()))
            {
                // no accopunt loaded so it is a null object at property Account
                if ((entity as IHaveAccount).Account == null)
                {
                    RepositoryContext.Entry(entity as IHaveAccount)
                    .Reference(e => e.Account)
                    .Load();
                }

                account = (entity as IHaveAccount).Account;
            }

            // it is an account
            else
            {
                account = entity as Account;
            }

            // loading of the credential
            RepositoryContext.Entry(account)
            .Reference(a => a.Credential)
            .Load();
        }
Example #4
0
 public void CreateOrder(Order order)
 {
     Create(order);
     RepositoryContext.Entry(order.User).State = EntityState.Unchanged;
     foreach (var orderItem in order.OrderItems)
     {
         orderItemRepository.CreateOrderItem(orderItem);
     }
 }
Example #5
0
 internal void UpdateOrderItem(OrderItem orderItem)
 {
     RepositoryContext.Entry(orderItem.Product).State = EntityState.Unchanged;
     if (orderItem.Order != null)
     {
         RepositoryContext.Entry(orderItem.Order).State = EntityState.Unchanged;
     }
     Update(orderItem);
 }
Example #6
0
        public void AddOrUpdateOrderItem(Order currentOrder, OrderItem newOrderItem)
        {
            var existingOrderItem = currentOrder.OrderItems.FirstOrDefault(x => x.Product.Id == newOrderItem.Product.Id);

            if (existingOrderItem == null)
            {
                orderItemRepository.CreateOrderItem(newOrderItem);
                currentOrder.OrderItems.Add(newOrderItem);
            }
            else
            {
                existingOrderItem.Quantity += newOrderItem.Quantity;
                orderItemRepository.UpdateOrderItem(existingOrderItem);
            }
            RepositoryContext.Entry(currentOrder.User).State = EntityState.Unchanged;
            Update(currentOrder);
        }
Example #7
0
 public void Update(TEntity entity)
 {
     _dbContext.Set <TEntity>().Attach(entity);
     _dbContext.Entry(entity).State = EntityState.Modified;
 }
 protected EntityEntry <TEntity> With <TEntity>(TEntity entry) where TEntity : class
 {
     return(RepositoryContext.Entry(entry));
 }
Example #9
0
 public void CreateProduct(Product product)
 {
     Create(product);
     RepositoryContext.Entry(product.Restaurant).State = EntityState.Unchanged;
 }