//this is used for billing controller public bool SetSubscription(string UserCode, int IdPlan, string AppToken) { //verificar existencia de la app token //obtiene ID de producto int idProduct = productsRepository.GetProductId(AppToken); if (idProduct == 0) { throw new Contract.Exceptions.ProductsNotFoundException("No se encontró un producto con el ProductToken " + AppToken, null); } //obtener usuario segun el app token y external code var user = usersRepository.GetUser(UserCode, idProduct); if (user == null) { throw new Contract.Exceptions.UserNotFoundException("No se encontró un usuario con el UserCode " + UserCode, null); } //verificar si existe una suscripcion actual. Si existe se cambia el IDPERFIL. var sub = subscriptionsRepository.GetUserCurrentSubscription(user.IdUser); if (sub == null) { //Si no existe, se crea la suscripcion. subscriptionsRepository.NewSubscription(new Repository.EntityFramework.Subscriptions { Active = true, DateCreated = DateTime.Now, ExternalCode = "", IdProfile = IdPlan, IdUser = user.IdUser, IsCurrent = true, RenewalDay = DateTime.Now.Day, LastRenewal = DateTime.Now }); } else { subscriptionsRepository.SetSubscriptionProfile(sub.IdSubscription, IdPlan); } (new Repository.Implementation.EventLogRepository()).SetLog("POR PINCHAR ANALYTICS", "GA"); try { //avisa a google analytics si es que tiene el codigo var producto = productsRepository.GetProduct(idProduct); if (producto != null) { (new Repository.Implementation.EventLogRepository()).SetLog("EXISTE PRODUCTO " + producto.IdProduct, "GA"); (new Repository.Implementation.EventLogRepository()).SetLog("CODIGO ANALYTICS " + producto.CodeAnalytics, "GA"); //si existe el codigo para el producto if (!String.IsNullOrEmpty(producto.CodeAnalytics)) { (new Repository.Implementation.EventLogRepository()).SetLog("TIENE CODIGO ANALYTICS " + producto.CodeAnalytics, "GA"); var profile = profilesRepository.GetProfile(IdPlan); if (profile != null) { (new Repository.Implementation.EventLogRepository()).SetLog("TIENE PROFILE " + IdPlan + " (" + profile.Name + ")", "GA"); GoogleAnalyticsHelper.TrackEvent(producto.CodeAnalytics, @"usuario", @"registro", @"perfil", @"1"); } } } } catch (Exception ex) { //nothing } return(true); }