public static UserGroup PutUserGroup(UserGroup userGroup, AriUMContext ctx)
 {
     ctx.AttachCopy<UserGroup>(userGroup);
     ctx.SaveChanges();
     return userGroup;
 }
 public static User PutUser(User user, AriUMContext ctx)
 {
     // Password control
     if (user.Password != "" && user.Password != null)
     {
         user.Password = CntWebApiSecurity.GetHashCode(user.Password);
     }
     ctx.AttachCopy<User>(user);
     ctx.SaveChanges();
     return user;
 }
 public static Product PutProduct(Product product, AriUMContext ctx)
 {
     ctx.AttachCopy<Product>(product);
     ctx.SaveChanges();
     return product;
 }
 public static InvoiceLine PutInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx)
 {
     int invoiceLineId = invoiceLine.InvoiceLineId;
     int productId = 0;
     int invoiceId = 0;
     if (invoiceLine.Product != null)
     {
         productId = invoiceLine.Product.ProductId;
         invoiceLine.Product = null;
     }
     if (invoiceLine.Invoice != null)
     {
         invoiceId = invoiceLine.Invoice.InvoiceId;
         invoiceLine.Invoice = null;
     }
     ctx.AttachCopy<InvoiceLine>(invoiceLine);
     invoiceLine = (from il in ctx.InvoiceLines
                    where il.InvoiceLineId == invoiceLineId
                    select il).FirstOrDefault<InvoiceLine>();
     invoiceLine.Product = (from p in ctx.Products
                            where p.ProductId == productId
                            select p).FirstOrDefault<Product>();
     invoiceLine.Invoice = (from i in ctx.Invoices
                            where i.InvoiceId == invoiceId
                            select i).FirstOrDefault<Invoice>();
     ctx.SaveChanges();
     return invoiceLine;
 }
 public static Invoice PutInvoice(Invoice invoice, AriUMContext ctx)
 {
     //Customer c = invoice.Customer;
     //invoice.Customer = null;
     //ctx.AttachCopy<Invoice>(invoice);
     //invoice.Customer = c;
     int customerId = 0;
     int invoiceId = invoice.InvoiceId;
     if (invoice.Customer != null)
     {
         customerId = invoice.Customer.CustomerId;
         invoice.Customer = null;
     }
     ctx.AttachCopy <Invoice>(invoice);
     if (customerId != 0)
     {
         invoice = (from i in ctx.Invoices
                    where i.InvoiceId == invoiceId
                    select i).FirstOrDefault<Invoice>();
         invoice.Customer = (from cus in ctx.Customers
                             where cus.CustomerId == customerId
                             select cus).FirstOrDefault<Customer>();
     }
     ctx.SaveChanges();
     return invoice;
 }
 public static Customer PutCustomer(Customer customer, AriUMContext ctx)
 {
     ctx.AttachCopy<Customer>(customer);
     ctx.SaveChanges();
     return customer;
 }