private void SaveOrder(OrderHeader objOrder) { try { BaseEntity objEntity = new BaseEntity(); tBaseDetailOrderList objListDetail = new tBaseDetailOrderList(); for (int i = 0; i < objOrder.ListOrderDetail.Count; i++) { objListDetail.Add(new tBaseDetailOrder() { ProductId = objOrder.ListOrderDetail[i].Product.ID, Price = objOrder.ListOrderDetail[i].Product.UnitPrice, Quantity = objOrder.ListOrderDetail[i].Quantity, PriceOffer = objOrder.ListOrderDetail[i].Product.PriceOffer, Status = Convert.ToByte(EnumStatus.Enabled) }); } Boolean success; if (objOrder.ID == 0) { objOrder.Status = Convert.ToByte(EnumOrderStatus.PendienteEntrega); objOrder.PaymentStatus = Convert.ToByte(EnumPaymentStatus.PendientePago); success = OrderBL.Instance.Insertar_Pedido(ref objEntity, ref objOrder, objListDetail); if (objEntity.Errors.Count == 0) { if (success) { Response.Redirect("Confirmation.aspx", false); } else { this.Message(EnumAlertType.Info, "No se pudo guardar la Orden"); return; } } else { this.Message(EnumAlertType.Info, objEntity.Errors[0].Error.Message); return; } } else { this.Message(EnumAlertType.Info, "No se pudo guardar la Orden"); } } catch (Exception ex) { this.Message(EnumAlertType.Error, "Ocurrio un error al guardar la Orden"); } }
public static object RegistroOrden(String clientes, String productos, String descripcion, String cantidad, String precio, String estado) { Object objReturn = new Object(); BaseEntity objBase = new BaseEntity(); try { #region Obtener Cliente JavaScriptSerializer sr = new JavaScriptSerializer(); List <String> lstClientesString = sr.Deserialize <List <String> >(clientes); List <Int32> lstClientesInt = new List <Int32>(); if (lstClientesString.Count > 0) { if (lstClientesString[0].Equals("multiselect-all")) { lstClientesString.RemoveAt(0); } lstClientesInt = lstClientesString.Select(Int32.Parse).ToList(); } else { lstClientesInt.Insert(0, 0); } #endregion #region Obtener Producto JavaScriptSerializer srp = new JavaScriptSerializer(); List <String> lstProductString = srp.Deserialize <List <String> >(productos); List <Int32> lstProductsInt = new List <Int32>(); if (lstProductString.Count > 0) { if (lstProductString[0].Equals("multiselect-all")) { lstProductString.RemoveAt(0); } lstProductsInt = lstProductString.Select(Int32.Parse).ToList(); } else { lstProductsInt.Insert(0, 0); } #endregion Int32 CustomerId = (lstClientesInt.Count > 0) ? lstClientesInt[0] : 0; Int32 ProductId = (lstProductsInt.Count > 0) ? lstProductsInt[0] : 0; Decimal UnitPrice = Convert.ToDecimal(precio); Int32 Quantity = Convert.ToInt32(cantidad); Byte Status = Convert.ToByte(estado); AppResource obj = ResourceBL.Instance.AppResource_GetByID(ref objBase, ProductId); if (objBase.Errors.Count == 0) { if (obj != null) { OrderHeader orderHeader = new OrderHeader(); obj.NameResource = Config.Impremtawendomain + obj.NameResource; OrderDetail Detalle = new OrderDetail(); Detalle.Product = obj; Detalle.ProductId = ProductId; Detalle.Product.UnitPrice = UnitPrice; Detalle.Quantity = Quantity; Detalle.CreatedBy = CustomerId; Detalle.UpdatedBy = CustomerId; Detalle.Status = (Status == 1) ? Convert.ToByte(EnumStatus.Enabled) : Convert.ToByte(0); orderHeader.IsCotization = 1; orderHeader.Description = descripcion; orderHeader.ListOrderDetail.Add(Detalle); Detalle.CalculateTotalPricexProduct(); orderHeader.CalculateTotals(); orderHeader.Customer = new Customer(); orderHeader.Customer.CustomerId = CustomerId; tBaseDetailOrderList objListDetail = new tBaseDetailOrderList(); for (int i = 0; i < orderHeader.ListOrderDetail.Count; i++) { objListDetail.Add(new tBaseDetailOrder() { ProductId = orderHeader.ListOrderDetail[i].Product.Id, Price = orderHeader.ListOrderDetail[i].Product.UnitPrice, Quantity = orderHeader.ListOrderDetail[i].Quantity, CreatedBy = orderHeader.Customer.CustomerId, UpdatedBy = orderHeader.Customer.CustomerId, Status = Convert.ToByte(EnumStatus.Disabled) }); } Boolean success = OrderBL.Instance.Insertar_Pedido(ref objBase, ref orderHeader, objListDetail); if (success) { String UrlPaymentOrder = String.Format("{0}?ordid={1}", Config.impremtawendomainReview, HttpUtility.UrlEncode(Encryption.Encrypt(Convert.ToString(orderHeader.OrderId)))); objReturn = new { Result = "Ok", Msg = "Orden Registrada correctamente.", UrlPaymentOrder = UrlPaymentOrder }; } else { objReturn = new { Result = "NoOk", Msg = "No se pudo registrar la Orden.", }; } } } else { objReturn = new { Result = "NoOk", Msg = "No se pudo registrar la Orden.", }; } } catch (Exception exception) { objReturn = new { Result = "NoOk", Msg = "No se pudo registrar la Orden.", }; } return(objReturn); }