예제 #1
0
        public ActionResult Next(string form, int plan, string user, int result)
        {
            //obtengo el formulario
            var formulario = productsFormsRepository.GetProductForm(form);

            //verificar existencia de la app token
            //obtiene ID de producto
            int idProduct = (int)formulario.IdProduct;

            if (idProduct == 0)
            {
                return(Content("ERROR: No se encontro el producto"));
            }

            //obtener usuario segun el app token y external code
            var user_r = usersRepository.GetUser(user, idProduct);

            if (user_r == null)
            {
                return(Content("ERROR: El usuario no existe"));
            }

            //paginas
            var url_ok    = user_r.Products.BillingUrlOk;
            var url_error = user_r.Products.BillingUrlError;

            //si se selecciona resultado con error en el pago, retorna a pantalla de error antes de cambiar la suscripcion
            if (result == 0)
            {
                return(Redirect(url_error));
            }

            //verificar si existe una suscripcion actual. Si existe se cambia el IDPERFIL.
            var sub = subscriptionsRepository.GetUserCurrentSubscription(user_r.IdUser);

            if (sub == null)
            {
                //Si no existe, se crea la suscripcion.

                subscriptionsRepository.NewSubscription(new Repository.EntityFramework.Subscriptions
                {
                    Active       = true,
                    DateCreated  = DateTime.Now,
                    ExternalCode = "",
                    IdProfile    = plan,
                    IdUser       = user_r.IdUser,
                    IsCurrent    = true,
                    RenewalDay   = DateTime.Now.Day
                });
            }
            else
            {
                subscriptionsRepository.SetSubscriptionProfile(sub.IdSubscription, plan);
            }

            //retorna a la pagina de retorno EXITOSO del producto
            return(Redirect(user_r.Products.BillingUrlOk));
        }
예제 #2
0
        /// <summary>
        /// Update dimension value, it will check dimension type for
        /// </summary>
        /// <param name="idProduct">ID Product</param>
        /// <param name="idClient">ID Client (external code)</param>
        /// <param name="idProfile">ID Profile</param>
        /// <param name="idDimension">ID Dimension (must to be consumible)</param>
        /// <param name="value">New value for dimension</param>
        /// <returns></returns>
        public ActionResponse UpdateValueDimensionAction(int idProduct, int idClient, int idProfile, int idDimension, decimal value)
        {
            try
            {
                // Check if product exists
                var oProduct = this.productsRepository.GetProduct(idProduct);
                if (oProduct == null)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existe el producto", null));
                }

                // Check if client (user) exists or it's linked to product
                var oUser = this.usersRepository.GetUserv2(idClient.ToString(), idProduct);
                if (oUser == null)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El usuario no existe o no está relacionado con el producto", null));
                }
                if (!oUser.Active.Value)
                {
                    return(utilities.Response((int)CodeStatusEnum.CONFLICT, "El usuario indicado no se encuentra activo en la plataforma", null));
                }
                int idUser = oUser.IdUser; // ID USER FREEMIUM

                // Check if profile exists
                var oProfile = profilesRepository.GetProfile(idProfile);
                if (oProfile == null)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El perfil no existe en el sistema", null));
                }

                // Check if product has profiles associated and idProfile is part of it
                var profiles = oProduct.Profiles;
                if (profiles.Count <= 0)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El producto no posee perfiles configurados", null));
                }
                bool isValidProfile = false;
                foreach (var oProf in profiles)
                {
                    if (oProf.IdProfile == idProfile)
                    {
                        isValidProfile = true;
                        break;
                    }
                }

                if (!isValidProfile)
                {
                    return(utilities.Response((int)CodeStatusEnum.CONFLICT, "El perfil no tiene relación con el producto", null));
                }

                // Check if dimension exists
                var oDimension = this.dimensionsRepository.GetDimension(idDimension);
                if (oDimension == null)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existe ninguna dimensión con el identificador proporcionado", null));
                }

                // Check dimension is related to profile across dimensioncategories
                var dimensionCategories = oProduct.DimensionsCategories;
                if (dimensionCategories.Count <= 0)
                {
                    return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existen categorías de dimensión asociadas al producto", null));
                }

                bool okDimension = false;
                foreach (var oDimensionCategory in dimensionCategories)
                {
                    // Will find dimension
                    if (oDimensionCategory.IdDimensionCategory == oDimension.IdDimensionCategory)
                    {
                        okDimension = true;
                        break;
                    }
                }
                if (!okDimension)
                {
                    return(utilities.Response((int)CodeStatusEnum.CONFLICT, "La dimensión no está relacionada a ninguna categoría", null));
                }


                // Update value dimension
                // If dimension is consumible will update it
                if (oDimension.IdDimensionType == (int)DimensionTypeEnum.CONSUMIBLE)
                {
                    // Find subscription
                    var subscription = subscriptionsRepository.GetUserCurrentSubscription(idUser);
                    if (subscription == null)
                    {
                        return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar la subscripción del usuario", null));
                    }

                    // Update value
                    var userDimension = usersDimensionsRepository.GetUserDimension(idDimension, subscription.IdSubscription);
                    if (userDimension == null)
                    {
                        return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar la dimensión del usuario", null));
                    }
                    if (userDimension.CurrentValue == null)
                    {
                        return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar el valor de la dimensión del usuario", null));
                    }

                    decimal oldValueX = userDimension.CurrentValue.Value;

                    bool action = usersDimensionsRepository.UpdateUserDimensionValue(userDimension.IdUserDimension, value);

                    DimensionTypeEnum            dimensionTypeEnum = (DimensionTypeEnum)oDimension.IdDimensionType.Value;
                    UpdateValueDimensionResponse response          = new UpdateValueDimensionResponse
                    {
                        idDimension       = idDimension,
                        nameDimension     = oDimension.Description,
                        tagName           = oDimension.TagName,
                        idDimensionType   = oDimension.IdDimensionType.Value,
                        nameDimensionType = dimensionTypeEnum.ToString(),
                        oldValue          = oldValueX,
                        currentValue      = value
                    };


                    return(utilities.Response((int)CodeStatusEnum.OK, "OK", response));
                }
                else
                {
                    return(utilities.Response((int)CodeStatusEnum.CONFLICT, "La dimensión no es del tipo consumible", null));
                }
            }
            catch (Exception e)
            {
                return(utilities.Response((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema: " + e.Message, null));
            }
        }
예제 #3
0
        public ActionResult Index(string form, string user, string country)
        {
            //validaciones iniciales
            if (String.IsNullOrWhiteSpace(form))
            {
                throw new HttpException(404, "Debes indicar el parametro FORM");
            }

            if (String.IsNullOrWhiteSpace(user))
            {
                throw new HttpException(404, "Debes indicar el parametro USER");
            }



            ViewBag.Pais       = country;
            ViewBag.Formulario = form;

            //obtengo el formulario
            var formulario = productsFormsRepository.GetProductForm(form);

            if (formulario == null)
            {
                throw new HttpException(404, "Formulario no existe");
            }

            if (formulario.IdProduct == null)
            {
                throw new HttpException(404, "Formulario no relacionado a un producto");
            }

            if (!usersRepository.UserExist(user, (int)formulario.IdProduct))
            {
                // throw new HttpException(404, "El usuario no existe para este producto");
                //usersRepository.CreateUser(user, (int)formulario.IdProduct);
            }


            //obtengo listado de perfiles
            var perfiles = profilesRepository.GetProfiles((int)formulario.IdProduct).Where(e => e.Featured == true);

            //obtengo perfiles del servicio de COBRO
            var cobros = cobrosRepository.GetCobros((int)formulario.IdProduct); //IDAPP es IDPROD

            List <Planes> planes = new List <Planes>();

            foreach (var item in perfiles)
            {
                var cobro = cobros.FirstOrDefault(e => e.IdPlan == item.IdProfile && e.Principal == 1);

                planes.Add(new Planes
                {
                    Nombre           = item.Name,
                    Valor            = (cobro != null)? cobro.Monto : "-",
                    Plan             = item.IdProfile,
                    Caracteristicas  = item.Description.Split(','),
                    Featured         = item.Featured == null ? false : (bool)item.Featured,
                    Motivator        = item.MotivatorText,
                    ShortDescription = item.ShortDescription,
                });
            }

            ViewBag.User = user;

            //obtengo usuario
            var u = usersRepository.GetUser(user, (int)formulario.IdProduct);

            //obtengo suscripcion actual del usuario
            var subs = subscriptionsRepository.GetUserCurrentSubscription(u.IdUser);

            int IdProfile = 0;

            if (subs == null)
            {
                //si no tiene suscripcion, le crea una en el estándar de suscrito sin suscripción.
                var profile = profilesRepository.GetStandardFreeSuscription(u.IdUser);
                IdProfile = profile.IdProfile;
            }
            else
            {
                IdProfile = (int)subs.IdProfile;

                if (subs.PromoActive == true)
                {
                    ViewBag.ActivePromo = 1;
                }
            }

            //datos del formulario
            ViewBag.UrlLogo          = formulario.UrlLogo;
            ViewBag.UrlBackground    = formulario.UrlBackground;
            ViewBag.ColorSuperiorBar = formulario.ColorSuperiorBar;
            ViewBag.CssClassFeatured = formulario.CssClassFeatured;
            ViewBag.CssClassActual   = formulario.CssClassActual;
            ViewBag.TitleColor       = formulario.TitleColor;
            ViewBag.FormTitle        = formulario.Title;
            ViewBag.CurrentIdProfile = IdProfile;

            return(View(planes));
        }