public bool SubmitOrder(OrderJSON order) { using (var dbContextTransaction = Context.Database.BeginTransaction()) { try { var new_item = new Order() { SaladAmount = order.SaladAmount, CheeseAmount = order.CheeseAmount, BaconAmount = order.BaconAmount, MeatAmount = order.MeatAmount, Address = order.Address, PhoneNumber = order.PhoneNumber, FirstName = order.FirstName, LastName = order.LastName, EmailAddress = order.EmailAddress }; Add(new_item, true); Commit(); dbContextTransaction.Commit(); dbContextTransaction.Dispose(); return(true); } catch (DbEntityValidationException e) { dbContextTransaction.Rollback(); dbContextTransaction.Dispose(); foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(false); } catch (Exception e) { dbContextTransaction.Rollback(); dbContextTransaction.Dispose(); throw e; } } }
public bool GetOrder(OrderJSON order) { var orderRep = IocConfig.Container.GetInstance <IOrderRepository>(); return(orderRep.SubmitOrder(order)); }
// ========== Get JSON ========== /** Returns this order in JSON format. **/ public string GetJSON() { OrderJSON orderJSON = new OrderJSON(); if (this.FileInfo != null) { orderJSON.Filename = this.FileInfo.Name; } orderJSON.Processed = this.Processed; orderJSON.Cancelled = this.Cancelled; orderJSON.Error = this.Error; orderJSON.Edit = this.Edit; orderJSON.DontArchive = this.DontArchive; orderJSON.Channel = this.Channel; orderJSON.OnHold = this.OnHold; orderJSON.CarrierType = this.CarrierType; orderJSON.OrderStatus = this.OrderStatus; orderJSON.OrderNumber = this.OrderNumber; orderJSON.OrderDate = this.OrderDate; orderJSON.OrderWeight = this.OrderWeight; orderJSON.OrderCost = this.OrderCost; orderJSON.ShippingCost = this.ShippingCost; orderJSON.TaxAmount = this.TaxAmount; orderJSON.ItemAmount = this.ItemAmount; orderJSON.CustomerName = this.CustomerName; orderJSON.CustomerPhone = this.CustomerPhone; orderJSON.CustomerMobile = this.CustomerMobile; orderJSON.CustomerEmail = this.CustomerEmail; orderJSON.Postcode = this.Postcode; orderJSON.Country = this.Country; orderJSON.CountryName = this.CountryName; orderJSON.City = this.City; orderJSON.Region = this.Region; orderJSON.Street = this.Street; if (this.Street.Length > 35 && string.IsNullOrEmpty(this.Locality)) { int breakPoint = 34; for (breakPoint = 34; breakPoint >= 0; breakPoint--) { if (this.Street [breakPoint] == ' ') { break; } } if (breakPoint > 0) { this.Locality = this.Street.Substring(breakPoint + 1); this.Street = this.Street.Substring(0, breakPoint); } } orderJSON.Locality = this.Locality; orderJSON.Items = this.Items; orderJSON.Tags = this.Tags; var alertNames = new List <string>(); if (this.OrderAlerts != null) { foreach (Alert alert in this.OrderAlerts) { alertNames.Add(alert.Name); } } if (this.RuleAlerts != null) { foreach (Alert alert in this.OrderAlerts) { alertNames.Add(alert.Name); } } if (alertNames.Count > 0) { orderJSON.Alerts = alertNames.ToArray(); } orderJSON.Carrier = this.Carrier != null ? this.Carrier.Name : ""; orderJSON.Service = this.Service; orderJSON.Enhancement = this.Enhancement; orderJSON.Format = this.Format; orderJSON.Zone = this.Zone != null ? this.Zone.name : ""; orderJSON.TrackingNumber = this.TrackingNumber; if (this.Labels != null) { List <string> labelNames = new List <string>(); foreach (Label label in this.Labels) { labelNames.Add(label.Name); } orderJSON.Labels = labelNames.ToArray(); } orderJSON.Translations = this.Translations; JavaScriptSerializer serializer = new JavaScriptSerializer(); return(serializer.Serialize(orderJSON)); }