Exemple #1
0
 public static void DeleteTestInovice(Invoice invoice)
 {
     using (var context = new ReturnFreightContext())
     {
         context.Invoices.Attach(invoice);
         context.Invoices.Remove(invoice);
         context.TrySaveChanges();
     }
 }
Exemple #2
0
        private ValidationResult TrySaveAndNotify(ReturnFreightContext context, Trip newTrip)
        {
            var savedChanges = context.TrySaveChanges();

            if (savedChanges.IsValid)
            {
                NotifyObservers(newTrip);
            }
            return(savedChanges);
        }
Exemple #3
0
 public static void DeleteTestOrder(Order o)
 {
     if (o != null)
     {
         using (var context = new ReturnFreightContext())
         {
             context.Orders.Attach(o);
             context.Orders.Remove(o);
             context.TrySaveChanges();
         }
     }
 }
Exemple #4
0
        public static Order CreateTestOrder(DateTime deadline, DateTime pickupDate, string from = "from", string to = "to")
        {
            var order = new Order(Customer, deadline, from, pickupDate, to);

            using (var context = new ReturnFreightContext())
            {
                context.Users.Attach(order.Customer);
                context.Orders.Add(order);
                context.TrySaveChanges();
            }
            return(order);
        }
Exemple #5
0
        public ValidationResult RegisterInvoice(Invoice invoice)
        {
            var validationResult = Validate(invoice);

            if (!validationResult.IsValid)
            {
                return(validationResult);
            }
            using (var context = new ReturnFreightContext())
            {
                context.Orders.Attach(invoice.Order);
                context.Invoices.Add(invoice);
                return(context.TrySaveChanges());
            }
        }
Exemple #6
0
 public void DeleteTestOrder()
 {
     //remove all created trips
     using (var context = new ReturnFreightContext())
     {
         var createdTrips = context.Trips.Where(
             t =>
             t.PrimaryOrder.Id == _primaryOrder.Id || t.PrimaryOrder.Id == _secondaryOrder.Id ||
             t.SecondaryOrder.Id == _primaryOrder.Id || t.SecondaryOrder.Id == _secondaryOrder.Id).ToList();
         context.Trips.RemoveRange(createdTrips);
         context.TrySaveChanges();
     }
     TestUtils.DeleteTestOrder(_primaryOrder);
     TestUtils.DeleteTestOrder(_secondaryOrder);
 }
Exemple #7
0
        public ValidationResult RegisterOrder(Order order)
        {
            var validationResult = Validate(order);

            if (!validationResult.IsValid)
            {
                return(validationResult);
            }
            using (var context = new ReturnFreightContext())
            {
                context.Users.Attach(order.Customer);
                context.Orders.Add(order);
                return(context.TrySaveChanges());
            }
        }