/// <summary> /// Getting Marketing Message By Id /// </summary> /// <param name="request"></param> /// <returns></returns> public GetMarketingMessageResponseById GetMarketingMessageById(GetMarketingMessageRequestById request) { GetMarketingMessageResponseById response = new GetMarketingMessageResponseById(); MarketingMessage messageViewmodel = marketingMessagesRopository.GetMarketingMessageById(request.MarketingMessageID); MarketingMessagesViewModel message = Mapper.Map <MarketingMessage, MarketingMessagesViewModel>(messageViewmodel); response.marketingMessagesViewModel = message; return(response); }
/// <summary> /// Updating Marketing Message /// </summary> /// <param name="request"></param> /// <returns></returns> public UpdateMarketingMessageResponse updateMarketingMessage(UpdateMarketingMessageRequest request) { UpdateMarketingMessageResponse response = new UpdateMarketingMessageResponse(); List <MarketingMessageAccountMapViewModel> accountViewModellist = new List <MarketingMessageAccountMapViewModel>(); List <MarketingMessageContentMapViewModel> messageViewModelList = new List <MarketingMessageContentMapViewModel>(); MarketingMessage marketingMessage = Mapper.Map <MarketingMessagesViewModel, MarketingMessage>(request.marketingMessagesViewModel); if (marketingMessage.MarketingMessageTitle.Length > 75) { throw new UnsupportedOperationException("[|Notification Title Is Maximum 75 characters.|]"); } foreach (MarketingMessageContentMapViewModel messageSubject in request.marketingMessagesViewModel.Messages) { if (messageSubject.Subject.Length > 75) { throw new UnsupportedOperationException("[|Message Subject Is Maximum 75 characters.|]"); } } bool isMessageTileUniue = marketingMessagesRopository.IsValidMarketingMessage(marketingMessage); if (!isMessageTileUniue) { Logger.Current.Verbose("Duplicate Notification Title is Identified," + marketingMessage.MarketingMessageTitle); var notifation = "[|Notification with Title|] \"" + marketingMessage.MarketingMessageTitle + "\" [|already exists.|] " + "[|Please choose a different Title|]"; throw new UnsupportedOperationException(notifation); } if (request.marketingMessagesViewModel.Status == (short)MarketingMessageStatus.Publish || request.marketingMessagesViewModel.Status == (short)MarketingMessageStatus.Active) { IEnumerable <string> accountMessage = marketingMessagesRopository.GetAllPublishedAccounts(request.marketingMessagesViewModel.AccountIDs, request.marketingMessagesViewModel.MarketingMessageID, request.marketingMessagesViewModel.ScheduleFrom, request.marketingMessagesViewModel.ScheduleTo); if (accountMessage.IsAny()) { string finalaccountMessage = string.Join(",", accountMessage); var notifation = "[| Message for " + finalaccountMessage + " already exits. Please exclude " + finalaccountMessage + " in selection. |]"; throw new UnsupportedOperationException(notifation); } } marketingMessagesRopository.UpdateMarketingMessage(marketingMessage); foreach (int accountid in request.marketingMessagesViewModel.AccountIDs) { MarketingMessageAccountMapViewModel accountviewmodel = new MarketingMessageAccountMapViewModel(); accountviewmodel.AccountID = accountid; accountviewmodel.MarketingMessageID = request.marketingMessagesViewModel.MarketingMessageID; accountViewModellist.Add(accountviewmodel); } marketingMessage.MarketingMessageAccountMaps = Mapper.Map <IEnumerable <MarketingMessageAccountMapViewModel>, IEnumerable <MarketingMessageAccountMap> >(accountViewModellist.ToArray()); if (marketingMessage.MarketingMessageAccountMaps != null) { marketingMessagesRopository.DeleteMarketingAccounts(request.marketingMessagesViewModel.MarketingMessageID); marketingMessagesRopository.InsertMarketingAccounts(marketingMessage.MarketingMessageAccountMaps); } foreach (MarketingMessageContentMapViewModel content in request.marketingMessagesViewModel.Messages) { MarketingMessageContentMapViewModel messageViewmodel = new MarketingMessageContentMapViewModel(); if (content.IsDeleted == false) { messageViewmodel.Subject = content.Subject; messageViewmodel.Icon = content.Icon; messageViewmodel.Content = content.Content; messageViewmodel.MarketingMessageID = marketingMessage.MarketingMessageID; messageViewModelList.Add(messageViewmodel); } } marketingMessage.MarketingMessageContentMaps = Mapper.Map <IEnumerable <MarketingMessageContentMapViewModel>, IEnumerable <MarketingMessageContentMap> >(messageViewModelList.ToArray()); if (marketingMessage.MarketingMessageContentMaps != null) { marketingMessagesRopository.DeleteMarketingMessageContents(marketingMessage.MarketingMessageID); marketingMessagesRopository.InsertMarketingMessageContents(marketingMessage.MarketingMessageContentMaps); } return(response); }