public bool SaveProduct(Models.Publisher.CreateProductModel _createModel, string UserIdentity, Models.Core.FileUpload fileUpload) { //Creamos los repositorios SiteRepository siteRepository = new SiteRepository(); AspNetUserRepository aspNetUserRepository = new AspNetUserRepository(); ProductTypeRepository productTypeRepository = new ProductTypeRepository(); PartnerRepository partnerRepository = new PartnerRepository(); ProductRepository productRepository = new ProductRepository(); //Obtenemos los conjuntos List <SiteEntity> sites = siteRepository.GetAll().ToList(); List <AspNetUserEntity> users = aspNetUserRepository.GetAll().ToList(); List <ProductTypeEntity> productstype = productTypeRepository.GetAll().ToList(); List <PartnerEntity> partners = partnerRepository.GetAll().ToList(); //Obtenemos las entidades deseadas. SiteEntity site = (from s in sites where s.IdSite == _createModel.SiteTypeSelecc select s).FirstOrDefault(); AspNetUserEntity user = (from u in users where u.Id == UserIdentity select u).FirstOrDefault(); ProductTypeEntity productType = (from pr in productstype where pr.IdProductType == _createModel.ProductTypeSelect select pr).FirstOrDefault(); PartnerEntity partner = (from p in partners where p.IdPartner == _createModel.ParterTypeSelect select p).FirstOrDefault(); ProductEntity product = new ProductEntity { //AspNetUser = user, AspNetUsers_Id = UserIdentity, IdProduct = Guid.NewGuid(), Price = _createModel.PriceSelecc, ShortDescription = _createModel.Name, FullDescription = string.Empty, StartTime = Helpers.DateTimeHelper.GetCurrentDateString(), EndTime = Helpers.DateTimeHelper.GetCurrentDateString(0, 30), RegistrationDate = DateTime.Now, SITE_IdSite = site.IdSite, PRODUCT_TYPE_IdProductType = productType.IdProductType, PARTNER_IdPartner = partner.IdPartner, Image = string.Empty, IsActive = true, IsPremium = _createModel.IsPremium }; if (fileUpload != null) { product.Image = Helpers.AzureStorageHelper.CreateBlobImageFile(fileUpload.FileData, fileUpload.Filextension); } else { product.Image = Helpers.AzureStorageHelper.CreateBlobImageFile(getImageFromUrl(""), ".png"); } productRepository.Add(product); if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_SUBSCRIBERS)) || _createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_PUSH_CREW)) || _createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_PUSH_ENGAGE))) { AddProductSettingEntity(product, "pushApiToken", _createModel.Token); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_MAIL_CHIMP))) { AddProductSettingEntity(product, "mailChimpApiToken", _createModel.Token); AddProductSettingEntity(product, "mailChimpList", _createModel.ListMCSelecc); AddProductSettingEntity(product, "mailChimpTemplate", Convert.ToString(_createModel.TemplateMCSelecc)); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_CAMPAIGN_MONITOR))) { AddProductSettingEntity(product, "campaignMonitorApiToken", _createModel.Token); AddProductSettingEntity(product, "campaignMonitorList", _createModel.ListCMSelecc); AddProductSettingEntity(product, "campaignMonitorClient", Convert.ToString(_createModel.ClientCMSelecc)); AddProductSettingEntity(product, "campaignMonitorSegment", Convert.ToString(_createModel.SegmentCMSelecc)); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_AWEBER))) { AddProductSettingEntity(product, "aweberApiToken", _createModel.Token); AddProductSettingEntity(product, "aweberList", _createModel.ListAWSelecc); AddProductSettingEntity(product, "aweberApplicationKey", _createModel.providerAWeberApiResult.ApplicationKey); AddProductSettingEntity(product, "aweberApplicationSecret", _createModel.providerAWeberApiResult.ApplicationSecret); AddProductSettingEntity(product, "aweberOAuthToken", _createModel.providerAWeberApiResult.OAuthToken); AddProductSettingEntity(product, "aweberOAuthTokenSecret", _createModel.providerAWeberApiResult.OAuthTokenSecret); AddProductSettingEntity(product, "aweberOauthVerifier", _createModel.providerAWeberApiResult.OauthVerifier); AddProductSettingEntity(product, "aweberCallbackURL", _createModel.providerAWeberApiResult.CallbackURL); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_SEND_GRID))) { AddProductSettingEntity(product, "sendGridApiToken", _createModel.Token); AddProductSettingEntity(product, "sendGridList", _createModel.ListSGSelecc); AddProductSettingEntity(product, "sendGridSender", _createModel.SenderSGSelecc); AddProductSettingEntity(product, "sendGridUnsubscribeGroup", _createModel.UnsubscribeGroupSGSelecc); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_ACTIVE_CAMPAIGN))) { AddProductSettingEntity(product, "activeCampaignApiToken", _createModel.Token); AddProductSettingEntity(product, "activeCampaignList", _createModel.ListACSelecc); AddProductSettingEntity(product, "activeCampaignUrl", _createModel.URLACSelecc); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_GETRESPONSE))) { AddProductSettingEntity(product, "getResponseApiToken", _createModel.Token); AddProductSettingEntity(product, "getResponseList", _createModel.ListGRSelecc); AddProductSettingEntity(product, "getResponseFromField", _createModel.FromFieldGRSelecc); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_ICONTACT))) { // Crear campaign y guardar el Id string IdCampaign = string.Empty; AddProductSettingEntity(product, "icontactIdCampaign", _createModel.IContact.IdCampaign); AddProductSettingEntity(product, "icontactApiAppId", _createModel.IContact.ApiAppId); AddProductSettingEntity(product, "icontactUserName", _createModel.IContact.ApiUserName); AddProductSettingEntity(product, "icontactUserPassword", _createModel.IContact.ApiUserPassword); AddProductSettingEntity(product, "icontactAccountId", _createModel.IContact.AccountId); AddProductSettingEntity(product, "icontactClientFolderId", _createModel.IContact.ClientFolderId); AddProductSettingEntity(product, "icontactIdList", _createModel.IContact.ListId); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_SENDINBLUE))) { //Store product settings AddProductSettingEntity(product, "sendinBlueApiKey", _createModel.Token); AddProductSettingEntity(product, "sendinBlueCategory", _createModel.SendinBlue.Category); AddProductSettingEntity(product, "sendinBlueFromEmail", _createModel.SendinBlue.FromEmail); AddProductSettingEntity(product, "sendinBlueListId", _createModel.SendinBlue.ListIds[0].ToString()); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_ONE_SIGNAL))) { AddProductSettingEntity(product, "oneSignalApiKey", _createModel.Token); AddProductSettingEntity(product, "oneSignalAppId", _createModel.ListAppOSSelecc); AddProductSettingEntity(product, "oneSignalAppKey", _createModel.AuthAppOSSelecc); } else if (_createModel.ParterTypeSelect.Equals(new Guid(Utils.Constants.PROVIDER_MAILJET))) { AddProductSettingEntity(product, "mailJetApiKey", _createModel.Token); AddProductSettingEntity(product, "mailJetList", _createModel.ListMJSelecc); AddProductSettingEntity(product, "mailJetSegment", _createModel.SegmentMJSelecc); AddProductSettingEntity(product, "mailJetSecretKey", _createModel.SecretKeyMJ); } return(true); }
public async Task <ActionResult> CreateProduct(Models.Publisher.CreateProductModel _createProduct, HttpPostedFileBase fileup) { if (ModelState.IsValid) { var productType = new Guid(Session["ProductTypeSelecc"].ToString()); var partner = new Guid(Session["PartnerSelecc"].ToString()); if (partner.Equals(new Guid(Utils.Constants.PROVIDER_DEFAULT_ADSMONETIZATION))) { var productTypeString = Session["ProductTypeSelecc"].ToString(); var site = new Guid(Session["SiteSelecc"].ToString()); var userId = Microsoft.AspNet.Identity.IdentityExtensions.GetUserId(User.Identity); var userDetail = _accessService.GetUserDetailByIdUser(new Guid(userId).ToString()); //llenamos el modelo MoneyAdsViewModel viewModel = _createProduct.adsManager.viewModel; viewModel.defaultAd.IdSite = site.ToString(); viewModel.defaultAd.name = _createProduct.Name; viewModel.defaultAd.typeSelected = "1"; CreateAds(viewModel); return(RedirectToAction("Settings", "MoneyAds")); } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_STICKY_ADSMONETIZATION))) { var productTypeString = Session["ProductTypeSelecc"].ToString(); var site = new Guid(Session["SiteSelecc"].ToString()); var userId = Microsoft.AspNet.Identity.IdentityExtensions.GetUserId(User.Identity); var userDetail = _accessService.GetUserDetailByIdUser(new Guid(userId).ToString()); //llenamos el modelo MoneyAdsViewModel viewModel = _createProduct.adsManager.viewModel; viewModel.defaultAd.IdSite = site.ToString(); viewModel.defaultAd.name = _createProduct.Name; viewModel.defaultAd.typeSelected = "2"; CreateAds(viewModel); return(RedirectToAction("Settings", "MoneyAds")); } else { var apiToken = Session["ApiToken"].ToString(); var price = Session["ProceSelecc"] == null ? _createProduct.PriceSelecc : Convert.ToDouble(Session["PriceSelecc"].ToString()); var site = new Guid(Session["SiteSelecc"].ToString()); var userId = Microsoft.AspNet.Identity.IdentityExtensions.GetUserId(User.Identity); var userDetail = _accessService.GetUserDetailByIdUser(new Guid(userId).ToString()); if (partner.Equals(new Guid(Utils.Constants.PROVIDER_MAIL_CHIMP))) { var listMailChimp = (string)TempData["ListMCSelecc"]; var templateMailChimp = Convert.ToInt32(TempData["TemplateMCSelecc"]); _createProduct.ListMCSelecc = listMailChimp; _createProduct.TemplateMCSelecc = templateMailChimp; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_CAMPAIGN_MONITOR))) { var listCampaignMonitor = (string)TempData["ListCMSelecc"]; var client = (string)TempData["ClientCMSelecc"]; var segment = (string)TempData["SegmentCMSelecc"]; _createProduct.ListCMSelecc = listCampaignMonitor; _createProduct.ClientCMSelecc = client; _createProduct.SegmentCMSelecc = segment; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_AWEBER))) { var listAWeber = (string)TempData["ListAWSelecc"]; _createProduct.providerAWeberApiResult = (ProviderAWeberApiResult)Session["ProviderAWeberApiResult"]; _createProduct.ListAWSelecc = listAWeber; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_GETRESPONSE))) { _createProduct.ListGRSelecc = (string)TempData["ListsGRSelecc"]; _createProduct.FromFieldGRSelecc = (string)TempData["FromFieldSelecc"]; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_SEND_GRID))) { _createProduct.ListSGSelecc = (string)TempData["ListsSGSelecc"]; _createProduct.SenderSGSelecc = (string)TempData["SenderSGSelecc"]; _createProduct.UnsubscribeGroupSGSelecc = (string)TempData["UnsubscribeGroupSGSelecc"]; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_ACTIVE_CAMPAIGN))) { _createProduct.ListACSelecc = (string)TempData["ListsACSelecc"]; _createProduct.URLACSelecc = (string)Session["WildCard"]; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_ICONTACT))) { _createProduct.ListICSelecc = (string)TempData["ListsICSelecc"]; _createProduct.IContact.ListId = _createProduct.ListICSelecc; //Generar campaƱa IContactService <ICampaign, IContactPostCampaignsResponse> iContactProvider = new IContactService <ICampaign, IContactPostCampaignsResponse>(); IContactRequest requestFrm = (IContactRequest)Session["IContactRequest"]; IContactPostCampaignRequest requestBody = new IContactPostCampaignRequest(); IContactPostCampaignsResponse responseCampaign = new IContactPostCampaignsResponse(); // Fill object requestBody.fromEmail = requestFrm.ApiUserName; requestBody.name = _createProduct.Name; requestBody.fromName = requestFrm.ApiUserName; responseCampaign = (IContactPostCampaignsResponse)iContactProvider.CreateCampaign(requestBody, requestFrm); _createProduct.IContact.IdCampaign = responseCampaign.campaigns[0].campaignId; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_SENDINBLUE))) { _createProduct.ListSBSelecc = (string)TempData["ListsSBSelecc"]; _createProduct.SendinBlue.ListIds = new List <int> { Convert.ToInt32(_createProduct.ListSBSelecc) }; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_ONE_SIGNAL))) { _createProduct.ListAppOSSelecc = (string)TempData["ListsAppOSSelecc"]; _createProduct.AuthAppOSSelecc = (string)TempData["AuthAppOSSelecc"]; } else if (partner.Equals(new Guid(Utils.Constants.PROVIDER_MAILJET))) { _createProduct.ListMJSelecc = (string)TempData["ListsMJSelecc"]; _createProduct.SegmentMJSelecc = (string)TempData["SegmentMJSelecc"]; } _createProduct.PriceSelecc = price; _createProduct.Token = apiToken; _createProduct.ProductTypeSelect = productType; _createProduct.ParterTypeSelect = partner; _createProduct.SiteTypeSelecc = site; //_createProduct.IsPremium = userDetail != null ? userDetail.IsPremium : false; if (_productService.SaveProduct(_createProduct, userId, GetFileUpload(fileup))) { ViewBag.Message = "Congratulations!!!"; } else { ViewBag.Message = "Error"; } } } await FillProductTypeAsync(); await FillCategory(); FillPrice(); await FillSites(); FillProductPremium(_createProduct); return(View(_createProduct)); }