/// <summary>
        /// Inserting Marketing Message
        /// </summary>
        /// <param name="marketingmessage"></param>
        /// <returns></returns>
        public ActionResult InsertMarketingMessage(string marketingmessage)
        {
            int userID = UserExtensions.ToUserID(this.Identity);
            MarketingMessagesViewModel marketingMessagesViewModel = JsonConvert.DeserializeObject <MarketingMessagesViewModel>(marketingmessage);

            marketingMessagesViewModel.AccountIDs      = marketingMessagesViewModel.SelectedAccountIDs;
            marketingMessagesViewModel.CreatedBy       = userID;
            marketingMessagesViewModel.CreatedDate     = DateTime.Now.ToUniversalTime();
            marketingMessagesViewModel.LastUpdatedBy   = userID;
            marketingMessagesViewModel.LastUpdatedDate = DateTime.Now.ToUniversalTime();
            if (marketingMessagesViewModel.ScheduleFrom != null && marketingMessagesViewModel.ScheduleTo != null)
            {
                marketingMessagesViewModel.ScheduleFrom = marketingMessagesViewModel.ScheduleFrom.Value.ToUserUtcDateTimeV2();
                marketingMessagesViewModel.ScheduleTo   = marketingMessagesViewModel.ScheduleTo.Value.ToUserUtcDateTimeV2();
            }
            InsertMarketingMessageResponse response = marketingService.insertMarketingMessage(new InsertMarketingMessageRequest()
            {
                RequestedBy = userID, marketingMessageViewModel = marketingMessagesViewModel
            });

            return(Json(new { success = true, response = response }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inserting Marketing Message
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public InsertMarketingMessageResponse insertMarketingMessage(InsertMarketingMessageRequest request)
        {
            InsertMarketingMessageResponse response = new InsertMarketingMessageResponse();

            List <MarketingMessageAccountMapViewModel> accountViewModellist = new List <MarketingMessageAccountMapViewModel>();
            List <MarketingMessageContentMapViewModel> messageViewModelList = new List <MarketingMessageContentMapViewModel>();

            MarketingMessage marketingMessage = Mapper.Map <MarketingMessagesViewModel, MarketingMessage>(request.marketingMessageViewModel);

            if (marketingMessage.MarketingMessageTitle.Length > 75)
            {
                throw new UnsupportedOperationException("[|Notification Title  Is Maximum 75 characters.|]");
            }
            foreach (MarketingMessageContentMapViewModel messageSubject in request.marketingMessageViewModel.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.marketingMessageViewModel.Status == (short)MarketingMessageStatus.Publish)
            {
                IEnumerable <string> accountMessage = marketingMessagesRopository.GetAllPublishedAccounts(request.marketingMessageViewModel.AccountIDs, 0, request.marketingMessageViewModel.ScheduleFrom, request.marketingMessageViewModel.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);
                }
            }

            int marketingMessageID = marketingMessagesRopository.InsertMarketingMessage(marketingMessage);

            foreach (int accountid in request.marketingMessageViewModel.AccountIDs)
            {
                MarketingMessageAccountMapViewModel accountviewmodel = new MarketingMessageAccountMapViewModel();
                accountviewmodel.AccountID          = accountid;
                accountviewmodel.MarketingMessageID = marketingMessageID;
                accountViewModellist.Add(accountviewmodel);
            }

            marketingMessage.MarketingMessageAccountMaps = Mapper.Map <IEnumerable <MarketingMessageAccountMapViewModel>, IEnumerable <MarketingMessageAccountMap> >(accountViewModellist.ToArray());
            if (marketingMessage.MarketingMessageAccountMaps != null)
            {
                marketingMessagesRopository.InsertMarketingAccounts(marketingMessage.MarketingMessageAccountMaps);
            }

            foreach (MarketingMessageContentMapViewModel content in request.marketingMessageViewModel.Messages)
            {
                MarketingMessageContentMapViewModel messageViewmodel = new MarketingMessageContentMapViewModel();
                if (content.IsDeleted == false)
                {
                    messageViewmodel.Subject            = content.Subject;
                    messageViewmodel.Icon               = content.Icon;
                    messageViewmodel.Content            = content.Content;
                    messageViewmodel.MarketingMessageID = marketingMessageID;
                    messageViewModelList.Add(messageViewmodel);
                }
            }

            marketingMessage.MarketingMessageContentMaps = Mapper.Map <IEnumerable <MarketingMessageContentMapViewModel>, IEnumerable <MarketingMessageContentMap> >(messageViewModelList.ToArray());
            if (marketingMessage.MarketingMessageContentMaps != null)
            {
                marketingMessagesRopository.InsertMarketingMessageContents(marketingMessage.MarketingMessageContentMaps);
            }
            return(response);
        }