// GET: Campaigns/Edit/5 public async Task <ActionResult> Edit(short?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Campaign campaign = await db.Campaigns.FindAsync(id); if (campaign == null) { return(HttpNotFound()); } var campaignEdit = new CampaignEditModel(); campaignEdit.CampaignId = campaign.CampaignId; campaignEdit.Name = campaign.Name; campaignEdit.Code = campaign.Code; campaignEdit.CodeCampaign = campaign.CodeCampaign; campaignEdit.Description = campaign.Description; campaignEdit.DiscountPercent = campaign.DiscountPercent; campaignEdit.RequiredAmount = campaign.RequiredAmount; campaignEdit.Enabled = campaign.Enabled; campaignEdit.EndDate = campaign.EndDate; campaignEdit.FreeShipping = campaign.FreeShipping; campaignEdit.OneTimeUse = campaign.OneTimeUse; campaignEdit.ProductCampaign = campaign.ProductCampaign; campaignEdit.StartDate = campaign.StartDate; campaignEdit.VariantCampaign = campaign.VariantCampaign; return(View(campaignEdit)); }
public ActionResult Edit(CampaignEditModel model) { try { var orgRoleId = _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId; if (ModelState.IsValid) { if (!IsAlreadyPublished(model.CampaignId)) { _campaignService.Save(model, orgRoleId); model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Campaign updated successfully"); } else { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Campaign has been already published"); } //return RedirectToAction("ManageCampaign"); } } catch (Exception ex) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Some Error occured while saving your record"); logger.Error("Message: " + ex.Message + " stack Trace: " + ex.StackTrace); } return(View(model)); }
public async Task <ActionResult> Create([Bind(Include = "CampaignId,Name,Description,Code,DiscountPercent,RequiredAmount" + "ProductCampaign,VariantCampaign,CodeCampaign,Enabled,OneTimeUse,FreeShipping,StartDate,EndDate")] CampaignEditModel campaignEdit) { if (ModelState.IsValid) { var campaign = new Campaign(); campaign.Name = campaignEdit.Name; campaign.Description = campaignEdit.Description; campaign.Code = campaignEdit.Code; campaign.DiscountPercent = campaignEdit.DiscountPercent; campaign.RequiredAmount = campaignEdit.RequiredAmount; campaign.ProductCampaign = campaignEdit.ProductCampaign; campaign.VariantCampaign = campaignEdit.VariantCampaign; campaign.CodeCampaign = campaignEdit.CodeCampaign; campaign.Enabled = campaignEdit.Enabled; campaign.OneTimeUse = campaignEdit.OneTimeUse; campaign.FreeShipping = campaignEdit.FreeShipping; campaign.StartDate = campaignEdit.StartDate; campaign.EndDate = campaignEdit.EndDate; db.Campaigns.Add(campaign); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(campaignEdit)); }
public void When_TwoEditConditionsOfSameTypePassed_Expect_AnErrorForConditionOfSameTypeThrown() { const string type = "SignUp"; var campaign = new CampaignEditModel() { Id = Guid.NewGuid().ToString(), FromDate = DateTime.UtcNow.AddMonths(1), Conditions = new List <ConditionEditModel> { new ConditionEditModel { Id = Guid.NewGuid().ToString(), Type = type }, new ConditionEditModel { Id = Guid.NewGuid().ToString(), Type = type } } }; var result = _campaignValidator.ShouldHaveValidationErrorFor(c => c.Conditions, campaign); result.WithErrorMessage(Phrases.CampaignConditionUnique); }
public IActionResult Edit(int id) { var model = new CampaignEditModel(); model.CampaignModel = campaignBLObject.GetById(id); model.AdsCreateModel = new AdvertisementSupplierCreateModel() { SupplierList = dropdownObj.GetSuppliers(), ChannelList = dropdownObj.GetChannels(), CampaignId = id }; IList <SelectListItem> list = Enum.GetValues(typeof(CampaignAction)).Cast <Enum>().Select(x => new SelectListItem { Text = x.ToString(), Value = x.ToString() }).ToList(); model.CampaignModel.ActionList = new SelectList(list, "Text", "Value"); model.Document = new DocumentModel() { DocumentTypes = dropdownObj.GetDocTypes(), CampaignId = id }; model.DocumentsList = docObj.GetDocsByCampaignId(id); return(View(model)); }
public void When_NoEditConditionPassed_Expect_AnErrorForConditionRequiredThrown() { var campaign = new CampaignEditModel { Id = Guid.NewGuid().ToString(), FromDate = DateTime.UtcNow.AddMonths(1), Conditions = new List <ConditionEditModel>() }; var result = _campaignValidator.ShouldHaveValidationErrorFor(c => c.Conditions, campaign); result.WithErrorMessage(Phrases.CampaignConditionNotNull); }
public void When_EarnRuleContentsAreNull_Expect_AnErrorForMissingContentThrown() { var earnRule = new CampaignEditModel() { Conditions = null, Contents = null }; var contentResult = _campaignValidator.ShouldHaveValidationErrorFor(c => c.Contents, earnRule); contentResult.WithErrorMessage(Phrases.RuleContentTypeNotNull); var conditionResult = _campaignValidator.ShouldHaveValidationErrorFor(c => c.Conditions, earnRule); conditionResult.WithErrorMessage(Phrases.CampaignConditionNotNull); }
public async Task <CampaignDetailResponseModel> UpdateAsync([FromBody] CampaignEditModel model) { try { var campaign = _mapper.Map <CampaignDetails>(model); if (!Guid.TryParse(model.Id, out _)) { _log.Info(Phrases.InvalidIdentifier, context: model.Id); return(new CampaignDetailResponseModel { ErrorCode = CampaignServiceErrorCodes.GuidCanNotBeParsed, ErrorMessage = Phrases.InvalidIdentifier }); } await _campaignService.UpdateAsync(campaign); return(new CampaignDetailResponseModel { ErrorCode = CampaignServiceErrorCodes.None }); } catch (EntityNotFoundException e) { _log.Info(string.Format(Phrases.EntityWithIdNotFound, "Campaign", model.Id), context: model.Id); return(new CampaignDetailResponseModel { ErrorCode = CampaignServiceErrorCodes.EntityNotFound, ErrorMessage = e.Message }); } catch (EntityNotValidException e) { _log.Info(Phrases.EntityNotValid, model); return(new CampaignDetailResponseModel { ErrorCode = CampaignServiceErrorCodes.EntityNotValid, ErrorMessage = e.Message }); } }
public void Save(CampaignEditModel model, long orgRoleId) { Campaign campaign = null; if (model.CampaignId > 0) { campaign = _campaignRepository.GetById(model.CampaignId); } campaign = GetModelToDomain(model, campaign, orgRoleId); campaign = _campaignRepository.Save(campaign); if (model.Assignments != null && model.Assignments.Any()) { _campaignAssignmentRepository.Save(campaign.Id, model.Assignments.Select(x => x.AssignedOrgRoleUserId).ToArray()); } var campaignActivity = _campaignActivityRepository.GetByCampaignId(model.CampaignId); if (campaignActivity != null && campaignActivity.Any() && (model.CampaignActivity == null || !model.CampaignActivity.Any())) { _campaignActivityRepository.DeleteByCampaignActivityIds(campaignActivity.Select(x => x.Id).ToArray()); } if (model.CampaignActivity != null && model.CampaignActivity.Any()) { var campaignActivityIds = new List <long>(); if (campaignActivity != null && campaignActivity.Any()) { campaignActivityIds = campaignActivity.Select(x => x.Id).ToList(); } var idsToPersist = model.CampaignActivity.Where(x => x.ActivityId > 0).Select(x => x.ActivityId).ToArray(); var activitiesToBeDelete = campaignActivityIds.Where(x => !idsToPersist.Contains(x)).Select(x => x); _campaignActivityRepository.DeleteByCampaignActivityIds(activitiesToBeDelete.ToArray()); SaveCampaignActivities(model.CampaignActivity, orgRoleId, campaign.Id); } }
private Campaign GetModelToDomain(CampaignEditModel model, Campaign inPersistence, long orgRoleId) { inPersistence = inPersistence ?? new Campaign { DataRecorderMetaData = new DataRecorderMetaData(orgRoleId, DateTime.Now, DateTime.Now) }; inPersistence.Name = model.Name; inPersistence.CampaignCode = model.CampaignCode; inPersistence.StartDate = model.StartDate.Value; inPersistence.EndDate = model.EndDate.Value; inPersistence.TypeId = model.TypeId; inPersistence.ModeId = model.ModeId; inPersistence.AccountId = model.AccountId; inPersistence.CustomTags = GetCustomTagString(model.CustomTags); inPersistence.Description = model.Description; inPersistence.IsPublished = model.IsPublished; inPersistence.DataRecorderMetaData.DataRecorderModifier = new OrganizationRoleUser(orgRoleId); inPersistence.DataRecorderMetaData.DateModified = DateTime.Now; return(inPersistence); }