public void CancelStockAndOrder(Order order, ref HopeLingerieEntities context)
        {
            if (stockValidate == null)
                return;

            order.OrderStatusId = 2; //estado de orden cancelada.
              //  hopeLingerieEntities.SaveChanges();

            foreach (var orderDetail in order.OrderDetails)
            {
                var productId = orderDetail.ProductId;
                var colorId = orderDetail.ColorId;
                var sizeId = orderDetail.SizeId;
                var quantity = orderDetail.Quantity;

                var stock = context.Stocks.SingleOrDefault(x => x.ProductId == productId && x.ColorId == colorId && x.SizeId == sizeId && x.Active);

                if (stock != null)
                {
                    stockValidate.AddStock(stock, quantity);
                }
            }

              //  hopeLingerieEntities.SaveChanges();
        }
Beispiel #2
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);
                }
            }
        }
        /*-------------------ORDER--------------------------*/
        public static IEnumerable<Color> GetColors(int productId)
        {
            var hopeLingerieEntities = new HopeLingerieEntities();

            var nullColor= new Color();
            nullColor.Code = "-- Seleccionar --";
            nullColor.ColorId = 0;

            var colors = hopeLingerieEntities.Colors.Where(x => x.ProductId == productId && x.Active).ToList();
            colors.Insert(0, nullColor);

            return colors;
        }
        public static IEnumerable<Size> GetSizes(int colorId)
        {
            var hopeLingerieEntities = new HopeLingerieEntities();
            var sizes = new List<Size>();

            var nullSize = new Size();
            nullSize.Code = "-- Seleccionar --";
            nullSize.SizeId = 0;

            try
            {
                var color = hopeLingerieEntities.Colors.Single(x => x.ColorId == colorId && x.Active);
                sizes = color.Sizes.ToList();

                sizes.Insert(0, nullSize);
                return sizes;
            }
            catch
            {
                sizes.Insert(0, nullSize);
                return sizes;
            }
        }
Beispiel #5
0
        // Este método de ACTUALIZACION DE ORDENES se ejecuta desde los metodos ClosedWithErrorsOrders, ClosedNotPayedOrders, InProcessOrders.
        // Envia el transactionId de la orden a DineroMail via WebService y luego actualiza el estado de la misma.
        // NO ACTUALIZA LA BASE DE DATOS, la actualización se hace desde el llamante para que sea transaccional.
        public void UpdateOrderStatus(string transactionIds, ref HopeLingerieEntities context)
        {
            PaymentService paymentService = new PaymentService();

            var transactions = transactionIds.Split(',');

            DineroMail dineroMail = new DineroMail();

            // Evalúa y actualiza el estado de cada orden en el sistema local con cada operación en dineromail.
            foreach (var merchantTransactionId in transactions)
            {
                ResultGetOperations resultOGetOperations = dineroMail.GetOperation(merchantTransactionId);

                // Metodos Dummy para Testing
                //var resultOGetOperations = GetDummyDeniedOperation(merchantTransactionId);
                //var resultOGetOperations = GetDummyErrorOperation(merchantTransactionId);
                //var resultOGetOperations = GetDummyOKPendingOperation(merchantTransactionId);
                //var resultOGetOperations = GetDummyOKAccreditedOperation(merchantTransactionId);
                //var resultOGetOperations = GetDummyOKCanceledOperation(merchantTransactionId);

                DoUpdateOrderStatus(resultOGetOperations, merchantTransactionId, ref context);
            }
        }
        public bool SubstractStock(List<OrderDetail> orderDetails, ref HopeLingerieEntities context)
        {
            if (stockValidate == null)
                return false;

            foreach (var orderDetail in orderDetails)
            {
                var productId = orderDetail.ProductId;
                var colorId = orderDetail.ColorId;
                var sizeId = orderDetail.SizeId;
                var quantity = orderDetail.Quantity;

                var stock = context.Stocks.SingleOrDefault(x => x.ProductId == productId && x.ColorId == colorId && x.SizeId == sizeId && x.Active);

                if (stock != null)
                {
                    stockValidate.SubstractStock(stock, quantity);

                    // Si el stock es negativo realiza el proceso pero genera un error y lo almacena en la base de datos.
                    if (!stockValidate.HasStock(stock))
                    {
                        context.ErrorLogs.AddObject(new ErrorLog { AddedDate = DateTime.Now, Message = "Error: Producto " + orderDetail.ProductId + " tiene Stock Real NEGATIVO" });
                        context.SaveChanges();
                        return false;
                    }
                }
            }
            return true;

               //     hopeLingerieEntities.SaveChanges();
        }
        public bool HasStock(List<OrderDetail> orderDetails, ref string productDescription, ref HopeLingerieEntities context)
        {
            if (stockValidate == null)
                return false;

            foreach (var orderDetail in orderDetails)
            {
                var productId = orderDetail.ProductId;
                var colorId = orderDetail.ColorId;
                var sizeId = orderDetail.SizeId;
                var quantity = orderDetail.Quantity;

                var stock = context.Stocks.SingleOrDefault(x => x.ProductId == productId && x.ColorId == colorId && x.SizeId == sizeId && x.Active);

                if (stock != null)
                {
                    if (!stockValidate.IsValidStock(stock, quantity))
                    {
                        productDescription = orderDetail.Product.Name + " (" + orderDetail.Product.Code + ") - Color:" + stock.Color.Code + " - Talle:" + stock.Size.Code;
                        return false;
                    }
                }
            }

            return true;
        }
Beispiel #8
0
        void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if ((Context.User != null) && (Context.User.Identity.IsAuthenticated))
            {
                string userInformation = String.Empty;//where the cookie info will be placed
                string roles = string.Empty;
                string email = string.Empty;
                string firstName = string.Empty;
                string lastName = string.Empty;

                // Create the roles cookie if it doesn't exist yet for this session.
                if ((Request.Cookies["cnstUserRole"] == null) || (Request.Cookies["cnstUserRole"].Value == ""))
                {
                    HopeLingerieEntities hopeLingerieEntities = new HopeLingerieEntities();

                    Customer customer = hopeLingerieEntities.Customers.SingleOrDefault(a => a.Email == Context.User.Identity.Name && a.Active);

                    if (customer != null)
                    {
                        if (customer.IsAdmin)
                            roles = "Admin";
                        else
                            roles = "User";

                        userInformation = roles + ";" + Context.User.Identity.Name + ";" + customer.FirstName + ";" + customer.LastName;

                        email = Context.User.Identity.Name;
                        firstName = customer.FirstName;
                        lastName = customer.LastName;

                        // Create a cookie authentication ticket.
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                            1,                              // version
                            User.Identity.Name,             // user name
                            DateTime.Now,                   // issue time
                            DateTime.Now.AddHours(1),       // expires every hour
                            false,                          // don't persist cookie
                            userInformation);

                        // Encrypt the ticket
                        String cookieStr = FormsAuthentication.Encrypt(ticket);

                        // Send the cookie to the client
                        Response.Cookies["cnstUserRole"].Value = cookieStr;
                        Response.Cookies["cnstUserRole"].Path = "/";
                        Response.Cookies["cnstUserRole"].Expires = DateTime.Now.AddMinutes(1);
                    }
                }
                else
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Context.Request.Cookies["cnstUserRole"].Value);
                    userInformation = ticket.UserData;

                    string[] cookieInfo = userInformation.Split(new char[] { ';' });
                    roles = cookieInfo[0];
                    email = cookieInfo[1];
                    firstName = cookieInfo[2];
                    lastName = cookieInfo[3];
                }

                CustomIdentity customIdentity = new CustomIdentity(email, firstName, lastName);
                HttpContext.Current.User = new CustomPrincipal(customIdentity, roles);
            }
        }