Esempio n. 1
0
        // Este proceso corre en la home, obtiene todas las ventas en estado "En Proceso" e itera las mismas comparando su fecha-hora de creación con la actual.
        // Aquellas que superen el tiempo permitido serán pasada a estado "Cancelada" y se reintegrará su stock.
        public void PurgeOrders()
        {
            var      purgeMinutes  = Convert.ToInt16(ConfigurationManager.AppSettings["PurgeMinutes"]);
            DateTime purgeDateTime = DateTime.Now.AddMinutes(-1 * purgeMinutes);
            // Pendientes cuya fecha-hora de alta sea menor al tiempo definido por PurgeMinutes
            var orders       = hopeLingerieEntities.Orders.Where(x => x.OrderStatusId == 1 && x.AddedDate < purgeDateTime && x.Active);
            var stockService = new StockService(new VirtualStock());

            if (orders.Count() > 0)
            {
                foreach (var order in orders)
                {
                    // Verifica si existe en dineromail, si no existe Cancela la orden y recupera Stock Virtual
                    UpdateOrderStatus(order.OrderId.ToString(), ref hopeLingerieEntities);
                }

                hopeLingerieEntities.SaveChanges();
            }
        }
Esempio n. 2
0
        // Este proceso corre en la home, obtiene todas las ventas en estado "En Proceso" e itera las mismas comparando su fecha-hora de creación con la actual.
        // Aquellas que superen el tiempo permitido serán pasada a estado "Cancelada" y se reintegrará su stock.
        public void PurgeOrders()
        {
            var purgeMinutes = Convert.ToInt16(ConfigurationManager.AppSettings["PurgeMinutes"]);
            DateTime purgeDateTime = DateTime.Now.AddMinutes(-1 * purgeMinutes);
            // Pendientes cuya fecha-hora de alta sea menor al tiempo definido por PurgeMinutes
            var orders = hopeLingerieEntities.Orders.Where(x => x.OrderStatusId == 1 && x.AddedDate < purgeDateTime && x.Active);
            var stockService = new StockService(new VirtualStock());

            if (orders.Count() > 0)
            {
                foreach (var order in orders)
                {
                    // Verifica si existe en dineromail, si no existe Cancela la orden y recupera Stock Virtual
                    UpdateOrderStatus(order.OrderId.ToString(), ref hopeLingerieEntities);
                }

                hopeLingerieEntities.SaveChanges();
            }
        }
Esempio n. 3
0
        // Actualiza los estados de la orden, si llega por Cancelada se le cambia el estado y se recupera el stock virtual tomado previamente.
        // NO ACTUALIZA LA BASE DE DATOS, la actualización se hace desde el llamante para que sea transaccional.
        private void DoUpdateOrderStatus(ResultGetOperations resultGetOperations, string merchantTransactionId, ref HopeLingerieEntities context)
        {
            var transactionId = Convert.ToInt32(merchantTransactionId);
            var order         = context.Orders.SingleOrDefault(a => a.OrderId == transactionId);

            // Si el estado de la Orden es En Proceso realiza la operación sino no hace nada
            if ((order == null) || (order.OrderStatusId != 1))
            {
                return;
            }

            // TODO: Poner estado que no se encontró el Trx_Id, poner estado 5 (FinalizadaConError) y recuperar stock
            if (resultGetOperations.Status == GetOperationsStatus.DENIED)
            {
                // No encontró el TransactionId en DineroMail
                var stockService = new StockService(new VirtualStock());
                // Cancela la orden y recupera Stock Virtual
                stockService.CancelStockAndOrder(order, ref context);

                //throw new DineroMailInterfaceException("ACCESO DENEGADO A DINEROMAIL" + resultGetOperations.Message);
            }
            else if (resultGetOperations.Status == GetOperationsStatus.ERROR)
            {
                throw new DineroMailInterfaceException("ERROR AL CONECTAR CON DINEROMAIL-" + resultGetOperations.Message);
            }
            else if (resultGetOperations.Status == GetOperationsStatus.OK)
            {
                // Debería tener una sola operación asociada al transactionId
                var operationDetail = resultGetOperations.Operations.LastOrDefault();

                if (operationDetail != null)
                {
                    if (operationDetail.State == OperationDetailState.PENDING)
                    {
                        //order.PaymentStatus = "Pendiente";
                        // TODO: Definir Status correcto
                        order.OrderStatusId = 5; //realizada sin cobrar
                    }
                    else if (operationDetail.State == OperationDetailState.ACCREDITED)
                    {
                        //order.PaymentStatus = "Pagada";
                        order.OrderStatusId = 8; // Finalizada
                    }
                    else if (operationDetail.State == OperationDetailState.CANCELED)
                    {
                        //  order.PaymentStatus = "Cancelada";
                        var stockService = new StockService(new VirtualStock());
                        // Cancela la orden y recupera Stock Virtual
                        stockService.CancelStockAndOrder(order, ref context);
                    }

                    order.PaymentMethod = operationDetail.PaymentMethod;
                }
                else  // en caso de que no se haya ingresado la orden a dineromail por fallo o porque se arrepintió, acredito stock, cancelo la orden y la pongo en finalizada con error.
                {
                    var stockService = new StockService(new VirtualStock());
                    // Cancela la orden y recupera Stock Virtual
                    stockService.CancelStockAndOrder(order, ref context);
                }
            }
        }
Esempio n. 4
0
        public virtual ActionResult DeliverOrder(int Id, FormCollection formCollection)
        {
            var order = hopeLingerieEntities.Orders.SingleOrDefault(a => a.OrderId == Id && a.Active);

            order.DeliveryBy = formCollection["DeliveryBy"];
            order.Comments = formCollection["Comments"];
            order.DeliveryDate = DateTime.Now;
            order.DeliveryStatusId = 2;

            var stockService = new StockService(new RealStock());
            var productDescription = string.Empty;

            // Si tiene Stock Real actualiza y graba
            if (!stockService.HasStock(order.OrderDetails.ToList(), ref productDescription, ref hopeLingerieEntities))
            {
                TempData["Message"] = "No existe stock del producto: " + productDescription + ". El pedido no puede ser entregado hasta que no actualice el stock!";

                return Redirect("/Backoffice/InformationBackOffice");
            }
            else
                stockService.SubstractStock(order.OrderDetails.ToList(), ref hopeLingerieEntities);

            hopeLingerieEntities.SaveChanges();

            return RedirectToAction("OrdersToDeliver");
        }
Esempio n. 5
0
        // Actualiza los estados de la orden, si llega por Cancelada se le cambia el estado y se recupera el stock virtual tomado previamente.
        // NO ACTUALIZA LA BASE DE DATOS, la actualización se hace desde el llamante para que sea transaccional.
        private void DoUpdateOrderStatus(ResultGetOperations resultGetOperations, string merchantTransactionId, ref HopeLingerieEntities context)
        {
            var transactionId = Convert.ToInt32(merchantTransactionId);
            var order = context.Orders.SingleOrDefault(a => a.OrderId == transactionId);

            // Si el estado de la Orden es En Proceso realiza la operación sino no hace nada
            if ((order == null) || (order.OrderStatusId != 1)) return;

            // TODO: Poner estado que no se encontró el Trx_Id, poner estado 5 (FinalizadaConError) y recuperar stock
            if (resultGetOperations.Status == GetOperationsStatus.DENIED)
            {
                // No encontró el TransactionId en DineroMail
                var stockService = new StockService(new VirtualStock());
                // Cancela la orden y recupera Stock Virtual
                stockService.CancelStockAndOrder(order, ref context);

                //throw new DineroMailInterfaceException("ACCESO DENEGADO A DINEROMAIL" + resultGetOperations.Message);
            }
            else if (resultGetOperations.Status == GetOperationsStatus.ERROR)
            {
                throw new DineroMailInterfaceException("ERROR AL CONECTAR CON DINEROMAIL-" + resultGetOperations.Message);
            }
            else if (resultGetOperations.Status == GetOperationsStatus.OK)
            {
                // Debería tener una sola operación asociada al transactionId
                var operationDetail = resultGetOperations.Operations.LastOrDefault();

                if (operationDetail != null)
                {
                    if (operationDetail.State == OperationDetailState.PENDING)
                    {
                        //order.PaymentStatus = "Pendiente";
                        // TODO: Definir Status correcto
                        order.OrderStatusId = 5; //realizada sin cobrar
                    }
                    else if (operationDetail.State == OperationDetailState.ACCREDITED)
                    {
                        //order.PaymentStatus = "Pagada";
                        order.OrderStatusId = 8; // Finalizada
                    }
                    else if (operationDetail.State == OperationDetailState.CANCELED)
                    {
                        //  order.PaymentStatus = "Cancelada";
                        var stockService = new StockService(new VirtualStock());
                        // Cancela la orden y recupera Stock Virtual
                        stockService.CancelStockAndOrder(order, ref context);
                    }

                    order.PaymentMethod = operationDetail.PaymentMethod;
                }
                else  // en caso de que no se haya ingresado la orden a dineromail por fallo o porque se arrepintió, acredito stock, cancelo la orden y la pongo en finalizada con error.
                {
                    var stockService = new StockService(new VirtualStock());
                    // Cancela la orden y recupera Stock Virtual
                    stockService.CancelStockAndOrder(order, ref context);
                }
            }
        }