public MarketingSourceEditModel Save(MarketingSourceEditModel model) { var marketingSource = Mapper.Map <MarketingSourceEditModel, MarketingSource>(model); if (marketingSource.Id == 0) { marketingSource.DataRecorderMetaData = new DataRecorderMetaData() { DateCreated = DateTime.Now } } ; else { var inDb = ((IUniqueItemRepository <MarketingSource>)_marketingSourceRepository).GetById(marketingSource.Id); marketingSource.DataRecorderMetaData = inDb.DataRecorderMetaData; marketingSource.DataRecorderMetaData.DateModified = DateTime.Now; } marketingSource = ((IUniqueItemRepository <MarketingSource>)_marketingSourceRepository).Save(marketingSource); _marketingSourceRepository.SaveMarketingSourceTerritories(marketingSource.Id, model.SelectedTerritories); model = Get(marketingSource.Id); return(model); }
public void Save() { var model = new MarketingSourceEditModel() { Id = 0, Description = "Some Description", Name = "Newsletter", SelectedTerritories = null }; model = _marketingSourceService.Save(model); Assert.IsNotNull(model); Assert.Greater(model.Id, 0); }
public ActionResult Edit(MarketingSourceEditModel model) { try { model.Territories = _territoryRepository.GetAllTerritoriesIdNamePair(TerritoryType.Advertiser); if (ModelState.IsValid) { _marketingSourceService.Save(model); model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("Marketing source created successfully!"); return(View(model)); } return(View(model)); } catch (Exception ex) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("System Failure: " + ex.Message); return(View(model)); } }