示例#1
0
 public ActionResult LaunchAdProduct(CampaignSetupModel model)
 {
     try
     {
         var dbContext = new SemplestModel.Semplest();
         var cr = new CreditCardRepository(dbContext);
         var sr = new StateRepository(dbContext);
         var pr = new PromotionRepository(dbContext);
         var bt = new BillTypeRepository(dbContext);
         var promo = pr.GetPromoitionFromCampaign(GetCustomerId(), model.ProductGroup.ProductGroupName,
                                                  model.ProductGroup.ProductPromotionName);
         var retVal = new ReturnState(false,false,"Not a credit card customer", null);
         if (model.BillType == bt.GetBillTypeCode("Credit Card"))
         {
             retVal = cr.ChargeCreditCard(new CustomerObject
                                                  {
                                                      Address1 = model.BillingLaunch.Address,
                                                      City = model.BillingLaunch.City,
                                                      Email = model.BillingLaunch.Email,
                                                      StateAbbr =
                                                          sr.GetStateNameFromCode(
                                                              int.Parse(model.BillingLaunch.StateCodeFK)),
                                                      ExpireDateMMYY =
                                                          model.BillingLaunch.ExpiryMonth +
                                                          model.BillingLaunch.ExpiryYear,
                                                      FirstName = model.BillingLaunch.FirstName,
                                                      LastName = model.BillingLaunch.LastName,
                                                      Phone = model.BillingLaunch.Phone,
                                                      ZipCode = model.BillingLaunch.Zip,
                                                      creditCardNumber = model.BillingLaunch.CardNumber
                                                  }, promo, model.BillType, model.ProductGroup.Budget);
         }
         try
         {
             if (!retVal.IsException && !retVal.IsValidationError)
             {
                 dbContext.SaveChanges();
                 var adEngines = new List<string>();
                 adEngines.AddRange(
                     promo.PromotionAdEngineSelecteds.Select(
                         pades => pades.AdvertisingEngine.AdvertisingEngine1));
                 var sw = new ServiceClientWrapper();
                 if (sw.ScheduleAddPromotionToAdEngine(GetCustomerId(), promo.ProductGroupFK,
                                                       promo.PromotionPK, adEngines.ToArray()))
                 {
                     pr.SetPromotionToLaunched(promo.PromotionPK);
                     dbContext.SaveChanges();
                 }
                 return Json(retVal.ReturnMessage);
             }
         }
         catch (Exception ex)
         {
             ExceptionHelper.LogException(ex);
             return Json(retVal.ReturnMessage);
         }
         if (!retVal.IsException && retVal.IsValidationError)
             return Json("Validation Error<~> " + retVal.ReturnMessage);
     }
     catch (Exception ex)
     {
         ExceptionHelper.LogException(ex);
     }
     return Json(ConfigurationManager.AppSettings["TechnicalDifficulties"]);
 }