public virtual HttpResponseMessage GetLogin(string login, string password) { using (AriUMContext ctx = new AriUMContext("AriUMDBConnection")) { WebApiTicket tck = CntWebApiSecurity.Login(login,password,30,ctx); if (tck == null) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Nombre de usuario o contraseña incorrecto"); } else { // we must add the new ticket to the database ctx.Add(tck); ctx.SaveChanges(); tck = ctx.CreateDetachedCopy<WebApiTicket>(tck, x => x.User); return Request.CreateResponse<WebApiTicket>(HttpStatusCode.OK, tck); } } }
public static bool DeleteProduct(Product product, AriUMContext ctx) { ctx.Delete(product); ctx.SaveChanges(); return true; }
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 bool DeleteInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx) { ctx.Delete(invoiceLine); ctx.SaveChanges(); return true; }
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 bool DeleteCustomer(Customer customer, AriUMContext ctx) { ctx.Delete(customer); ctx.SaveChanges(); return true; }
public static Customer PutCustomer(Customer customer, AriUMContext ctx) { ctx.AttachCopy<Customer>(customer); ctx.SaveChanges(); return customer; }
public static UserGroup PostUserGroup(UserGroup userGroup, AriUMContext ctx) { ctx.Add(userGroup); ctx.SaveChanges(); return userGroup; }
public static Product PostProduct(Product product, AriUMContext ctx) { ctx.Add(product); ctx.SaveChanges(); return product; }
public static InvoiceLine PostInvoiceLine(InvoiceLine invoiceLine, AriUMContext ctx) { if (invoiceLine.Invoice != null) { Invoice invoice = (from i in ctx.Invoices where i.InvoiceId == invoiceLine.Invoice.InvoiceId select i).FirstOrDefault<Invoice>(); invoiceLine.Invoice = invoice; } if (invoiceLine.Product != null) { Product product = (from p in ctx.Products where p.ProductId == invoiceLine.Product.ProductId select p).FirstOrDefault<Product>(); invoiceLine.Product = product; } ctx.Add(invoiceLine); ctx.SaveChanges(); return invoiceLine; }
public static Invoice PostInvoice(Invoice invoice, AriUMContext ctx) { ctx.Add(invoice); ctx.SaveChanges(); return invoice; }
public static Customer PostCustomer(Customer customer, AriUMContext ctx) { ctx.Add(customer); ctx.SaveChanges(); return customer; }
public static bool DeleteUser(User user, AriUMContext ctx) { ctx.Delete(user); ctx.SaveChanges(); return true; }
public static bool DeleteUserGroup(UserGroup userGroup, AriUMContext ctx) { ctx.Delete(userGroup); ctx.SaveChanges(); return true; }
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; }