public RepositoryResponse UpdateCustomer(Customer customer)
        {
            var originalCustomer = GetById(customer.CustomerId);

            if (originalCustomer == null)
            {
                return(RepositoryResponse.Failed("Customer do not exist: " + customer));
            }
            CustomerMapper.Update(originalCustomer, customer);
            _appDbContext.SaveChanges();

            return(RepositoryResponse.Success());
        }
        public RepositoryResponse DeleteCustomer(int id)
        {
            var customer = GetById(id);

            _appDbContext.Customers.Remove(customer);
            var count = _appDbContext.SaveChanges();

            if (count == 1)
            {
                return(RepositoryResponse.Success());
            }

            return(RepositoryResponse.Failed("Delete of customer " + id + " failed"));
        }
        public RepositoryResponse AddOrder(Order order)
        {
            try
            {
                _appDbContext.OrderItems.AddRange(order.OrderItems);
                EntityEntry <Customer> customerResult = _appDbContext.Customers.Add(order.Customer);
                EntityEntry <Location> locationResult = _appDbContext.Locations.Add(order.Location);
                EntityEntry <Order>    orderResult    = _appDbContext.Orders.Add(order);

                int result = _appDbContext.SaveChanges();
            }
            catch (Exception e) {
                return(RepositoryResponse.Failed(e.Message));
            }
            return(RepositoryResponse.Success());
        }
        public RepositoryResponse UpdateOrder(Order order)
        {
            var originalOrder = GetOrderById(order.OrderId);

            if (originalOrder == null)
            {
                return(RepositoryResponse.Failed("Order do not exist: " + order));
            }
            originalOrder.OrderItems  = order.OrderItems;
            originalOrder.ServiceDate = order.ServiceDate;
            originalOrder.Customer    = order.Customer;
            originalOrder.Location    = order.Location;

            _appDbContext.SaveChanges();

            return(RepositoryResponse.Success());
        }
 public RepositoryResponse AddCustomer(Customer customer)
 {
     try
     {
         EntityEntry <Customer> customerResult = _appDbContext.Customers.Add(customer);
         int result = _appDbContext.SaveChanges();
         if (result == 1)
         {
             return(RepositoryResponse.Success());
         }
     }
     catch (Exception e)
     {
         return(RepositoryResponse.Failed(e.Message));
     }
     return(RepositoryResponse.Failed("Add customer failed"));
 }
        public RepositoryResponse DeleteOrder(Order order)
        {
            var originalOrder = GetOrderById(order.OrderId);

            if (originalOrder == null)
            {
                return(RepositoryResponse.Failed("Order do not exist: " + order));
            }

            try
            {
                _appDbContext.Orders.Remove(order);
                int count = _appDbContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(RepositoryResponse.Failed(e.Message));
            }
            return(RepositoryResponse.Success());
        }