Exemple #1
0
		/// <summary>
		/// Default constructor. Creates a new model.
		/// </summary>
		public PostEditModel() {
			Template = new PostTemplate() {
				Preview = new HtmlString(
					"<table class=\"template\">" +
					"<tr><td></td></tr>" +
					"</table>"
					)
			} ;
		}
Exemple #2
0
        /// <summary>
        /// Gets the list model for all post templates.
        /// </summary>
        public static PostListModel Get()
        {
            PostListModel m = new PostListModel();

            m.Templates = PostTemplate.GetFields("posttemplate_id,posttemplate_name,posttemplate_type,posttemplate_created,posttemplate_updated",
                                                 new Params()
            {
                OrderBy = "posttemplate_name"
            });
            return(m);
        }
Exemple #3
0
        /// <summary>
        /// Gets the model for the template specified by the given id.
        /// </summary>
        /// <param name="id">The template id</param>
        /// <returns>The model</returns>
        public static PostEditModel GetById(Guid id)
        {
            PostEditModel m = new PostEditModel();

            m.Template = PostTemplate.GetSingle(id);
            if (m.Template.Properties == null)
            {
                m.Template.Properties = new List <string>();
            }

            return(m);
        }
Exemple #4
0
        /// <summary>
        ///     Inserts post template
        /// </summary>
        /// <param name="postTemplate">Post template</param>
        public virtual void InsertPostTemplate(PostTemplate postTemplate)
        {
            if (postTemplate == null)
            {
                throw new ArgumentNullException("postTemplate");
            }

            _postTemplateRepository.Insert(postTemplate);

            //event notification
            _eventPublisher.EntityInserted(postTemplate);
        }
        public static String GetPriceString(PostTemplate template)
        {
            StringBuilder builder = new StringBuilder();
            DataBase      db      = Singleton.GetInstance().Context;

            Single totalPrice = 0.0f;

            builder.Append("Чек:\n");

            builder.Append($"Тип поста ({GetPostTypeName((TypePostTime)template.isPinnedMessage)}): {GetPostTypePrice((TypePostTime)template.isPinnedMessage)} грн\n");
            if (template.isPinnedMessage == 0)
            {
                builder.Append("Старндартное сообщение постится в указаное время!\n");
            }
            else
            {
                builder.Append("Сообщение с закрепом постится каждый день в 12:00, удалятся каждый день в 11:00!\n");
            }

            //totalPrice += GetPostTypePrice((TypePostTime)template.isPinnedMessage);

            foreach (PostChannel item in template.PostChannel)
            {
                if (item.Channel != null)
                {
                    totalPrice += StartSession.NumberOfParticipants(item.Channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
                else
                {
                    Channel channel = db.GetChannel(item.ChannelId);
                    totalPrice += StartSession.NumberOfParticipants(channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
                builder.Append($"{item.Channel.ChannelName}: {item.Channel.Price} грн\n");
            }

            builder.Append($"\n");



            foreach (PostTime item in template.PostTime)
            {
                if (item.Time != System.DateTime.Today)
                {
                    totalPrice += PriceData.postTypeTime;

                    builder.Append($"\nПост на {item.Time.ToString("hh:mm:ss, dd.MM.yyyy")}: {PriceData.postTypeTime} грн");
                }
            }

            builder.Append($"\n\nВсего: {(Int32)totalPrice} грн");

            return(builder.ToString());
        }
        public static PostContent GetContent(TelegramBotClient client, PostTemplate template, System.Int32 order)
        {
            DataBase db = Singleton.GetInstance().Context;

            if (template.PostContent == null)
            {
                return(null);
            }

            PostContent content = db.GetPostContent(template, order);

            return(content);
        }
        public static PostTemplate CreateTemplate(AdUser user)
        {
            DataBase     db       = Singleton.GetInstance().Context;
            PostTemplate template = new PostTemplate
            {
                AdUser = user,
                Name   = "Шаблон"
            };

            db.AddTemplate(template);
            db.Save();

            return(template);
        }
        public static LabeledPrice[] GetLabelPrices(PostTemplate template)
        {
            List <LabeledPrice> prices = new List <LabeledPrice>();
            DataBase            db     = Singleton.GetInstance().Context;

            Single totalPrice = 0.0f;

            //totalPrice += GetPostTypePrice((TypePostTime)template.isPinnedMessage);
            String temp = "";

            if (template.isPinnedMessage == 0)
            {
                temp = "Старндартное сообщение постится в указаное время!\n";
            }
            else
            {
                temp = "Сообщение с закрепом постится каждый день в 12:00, удалятся каждый день в 11:00!\n";
            }

            prices.Add(new LabeledPrice($"Тип поста: {GetPostTypeName((TypePostTime)template.isPinnedMessage)} " + temp, (Int32)GetPostTypePrice((TypePostTime)template.isPinnedMessage) * 100));


            foreach (PostChannel item in template.PostChannel)
            {
                if (item.Channel != null)
                {
                    totalPrice = StartSession.NumberOfParticipants(item.Channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
                else
                {
                    Channel channel = db.GetChannel(item.ChannelId);
                    totalPrice = StartSession.NumberOfParticipants(channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
                if (totalPrice < 0)
                {
                    totalPrice = 1;
                }
                prices.Add(new LabeledPrice($"Чат {item.Channel.ChannelName}", ((Int32)item.Channel.Price * 100) + (Convert.ToInt32(totalPrice) * 100)));
            }

            foreach (PostTime item in template.PostTime)
            {
                if (item.Time != System.DateTime.Today)
                {
                    prices.Add(new LabeledPrice($"Пост на {item.Time.ToString("hh:mm:ss, dd.MM.yyyy:")} ", (Int32)PriceData.postTypeTime * 100));
                }
            }

            return(prices.ToArray());
        }
    protected void phPost_OnInit(object sender, EventArgs e)
    {
        PlaceHolder bsPostPlaceHolder = ((PlaceHolder)sender);

        Control findableControl = this.Page;

        // Post Detail
        if (PostDetail)
        {
            PostTemplate postDetail = (PostTemplate)LoadControl(Templates.PostDetail);

            PlaceHolder bsInnerPostPlaceHolder = (PlaceHolder)BSHelper.FindChildControl(postDetail, "BSPostPlaceHolder");

            if (bsInnerPostPlaceHolder != null)
            {
                bsInnerPostPlaceHolder.Controls.Add(LoadControl(Templates.Post));
            }

            bsPostPlaceHolder.Controls.Add(postDetail);
        }
        // Post
        else
        {
            bsPostPlaceHolder.Controls.Add(LoadControl(Templates.Post));
        }

        // Related Posts
        PlaceHolder bsRelatedPostsPlaceHolder = (PlaceHolder)BSHelper.FindChildControl(findableControl, "BSRelatedPostsPlaceHolder");

        if (bsRelatedPostsPlaceHolder != null)
        {
            bsRelatedPostsPlaceHolder.Controls.Add(LoadControl(Templates.RelatedPosts));
        }

        // Comments Template
        PlaceHolder bsCommentsPlaceHolder = (PlaceHolder)BSHelper.FindChildControl(findableControl, "BSCommentsPlaceHolder");

        if (bsCommentsPlaceHolder != null)
        {
            bsCommentsPlaceHolder.Controls.Add(LoadControl(Templates.Comments));
        }

        // Comment Form Template
        PlaceHolder bsCommentFormPlaceHolder = (PlaceHolder)BSHelper.FindChildControl(findableControl, "BSCommentFormPlaceHolder");

        if (bsCommentFormPlaceHolder != null)
        {
            bsCommentFormPlaceHolder.Controls.Add(LoadControl(Templates.CommentForm));
        }
    }
        public static void DeleteAllPosts(TelegramBotClient client, PostTemplate template)
        {
            DataBase db = Singleton.GetInstance().Context;

            Post[] posts = db.GetPosts(template);

            foreach (Post post in posts)
            {
                client.DeleteMessageAsync(post.ChannelId, post.MessageId);

                db.Remove(post);
            }

            db.Save();
        }
Exemple #11
0
        /// <summary>
        /// Gets the model for the post
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static EditModel GetById(Guid id, bool draft = true)
        {
            EditModel m = new EditModel();

            m.Post      = Piranha.Models.Post.GetSingle(id, draft);
            m.Template  = PostTemplate.GetSingle(m.Post.TemplateId);
            m.Permalink = Permalink.GetSingle(m.Post.PermalinkId);
            Category.GetByPostId(m.Post.Id, draft).ForEach(c => m.PostCategories.Add(c.Id));
            m.Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                  new Params()
            {
                OrderBy = "category_name"
            }), "Id", "Name", m.PostCategories);
            m.GetRelated();

            return(m);
        }
        public override async void Execute(TelegramBotClient botClient, System.Object message)
        {
            IStandartCommand standartCommand = new BackToContentKeyboard();
            ISplitName       splitName       = new BackToContentKeyboard();

            if (standartCommand.SetCallbackQuery(message, out _message))
            {
                return;
            }

            if (standartCommand.SetDataBase(out db))
            {
                return;
            }

            if (standartCommand.SetUserAndCheckIsNull(botClient, _message, out user, db))
            {
                return;
            }

            Int32 idPostTemplate = splitName.GetNameSplit(Name);

            Name = CommandsText.BackToContentKeyboard;
            if (IsBan.Ban(botClient, message))
            {
                if (GetPostTemplate(idPostTemplate))
                {
                    return;
                }

                ChangeUser();

                try
                {
                    AdUser       adUser       = db.GetAdUser(user.ID);
                    PostTemplate postTemplate = db.GetTempalte(adUser.User.ID, adUser.EditingPostTemplateId);

                    SendMessage(botClient);
                }
                catch (System.Exception ex)
                {
                    Log.Logging(ex);
                }
            }
        }
Exemple #13
0
        static void GeneratePost(Site site, Post p, PostTemplate postTemplate, IndexTemplate indexTemplate)
        {
            string dirPath  = Path.Combine(site.WebPath, p.Path);
            string htmlPath = Path.Combine(dirPath, "index.html");

            Directory.CreateDirectory(dirPath);
            if (Directory.Exists(p.SourceDir))
            {
                FileManager.Clone(p.SourceDir, dirPath);
            }

            var inst = indexTemplate.Create(site);

            inst["title"]    = p.Title;
            inst["tabs"]     = GenerateTabs(site, null, p);
            inst["contents"] = postTemplate.Generate(site, p);
            inst.Write(htmlPath);
        }
Exemple #14
0
		/// <summary>
		/// Default constructor. Creates a new model.
		/// </summary>
		public PostEditModel() {
			Permalink = new Permalink() {
				Id = Guid.NewGuid(),
				Type = Permalink.PermalinkType.ARCHIVE,
				NamespaceId = Config.ArchiveNamespaceId
			} ;
			Template = new PostTemplate() {
				PermalinkId = Permalink.Id,
				Preview = new HtmlString(
					"<table class=\"template\">\n" +
					"  <tr>\n" +
					"    <td></td>\n" +
					"  </tr>\n" +
					"</table>"
					)
			} ;
			HandlerPrefix = Application.Current.Handlers.Where(h => h.Id == "ARCHIVE").SingleOrDefault().UrlPrefix ;
		}
Exemple #15
0
		/// <summary>
		/// Default constructor. Creates a new model.
		/// </summary>
		public PostEditModel() {
			Permalink = new Permalink() {
				Id = Guid.NewGuid(),
				Type = Permalink.PermalinkType.ARCHIVE,
				NamespaceId = Config.ArchiveNamespaceId
			};
			Template = new PostTemplate() {
				PermalinkId = Permalink.Id,
				Preview = new HtmlString(
					"<table class=\"template\">\n" +
					"  <tr>\n" +
					"    <td></td>\n" +
					"  </tr>\n" +
					"</table>"
					)
			};
			HandlerPrefix = Application.Current.Handlers.Where(h => h.Id == "ARCHIVE").SingleOrDefault().UrlPrefix;
		}
Exemple #16
0
 /// <summary>
 /// Refreshes the current model.
 /// </summary>
 public void Refresh()
 {
     if (Post != null)
     {
         if (!Post.IsNew)
         {
             Post      = Piranha.Models.Post.GetSingle(Post.Id, true);
             Permalink = Permalink.GetSingle(Post.PermalinkId);
             Category.GetByPostId(Post.Id).ForEach(c => PostCategories.Add(c.Id));
             Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                                                                 new Params()
             {
                 OrderBy = "category_name"
             }), "Id", "Name", PostCategories);
         }
         Template = PostTemplate.GetSingle(Post.TemplateId);
         GetRelated();
     }
 }
Exemple #17
0
        /// <summary>
        /// Gets the model for the template specified by the given id.
        /// </summary>
        /// <param name="id">The template id</param>
        /// <returns>The model</returns>
        public static PostEditModel GetById(Guid id)
        {
            PostEditModel m = new PostEditModel();

            m.Template = PostTemplate.GetSingle(id);
            if (m.Template.Properties == null)
            {
                m.Template.Properties = new List <string>();
            }
            if (m.Template.PermalinkId != Guid.Empty)
            {
                m.Permalink = Permalink.GetSingle(m.Template.PermalinkId);
            }
            else
            {
                m.Template.PermalinkId = m.Permalink.Id;
            }

            return(m);
        }
        private void SetIncomeChannel(Int32 id, Single total, PostTemplate postTemplate = null)
        {
            DataBase           db      = Singleton.GetInstance().Context;
            List <ChannelInfo> channel = null;

            if (postTemplate == null)
            {
                channel = StartSession.Test(db.GetChannelsList(), id);
            }
            else
            {
                List <Channel> channels = new List <Channel>();
                foreach (var item in postTemplate.PostChannel)
                {
                    Channel Thischannel = db.GetChannel(item.ChannelId);
                    channels.Add(Thischannel);
                }
                channel = StartSession.Test(channels, id);
            }

            Int32 temp = channel.Count;

            foreach (var item in channel)
            {
                IncomeChannel incomeChannel = db.GetIncomeChannels((item.Channel.Id + 1000000000000) * -1);
                if (incomeChannel == null)
                {
                    db.SetValue <IncomeChannel>(new IncomeChannel()
                    {
                        ChannelId = (item.Channel.Id + 1000000000000) * -1, DateTime = System.DateTime.Today, SumIncome = total / temp
                    });
                }
                else
                {
                    incomeChannel.SumIncome = (total / temp) + incomeChannel.SumIncome;
                }
            }
            db.Save();
            SetIncome(channel, id, total);
            SetIncomeChannelAdmin(channel, total);
        }
Exemple #19
0
        public ActionResult PostTemplateAdd([Bind(Exclude = "Id")] PostTemplateModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Json(new DataSourceResult {
                    Errors = ModelState.SerializeErrors()
                }));
            }

            var template = new PostTemplate();

            template = model.ToEntity(template);
            _postTemplateService.InsertPostTemplate(template);

            return(new NullJsonResult());
        }
Exemple #20
0
        static void GeneratePost(Site site, Post p, PostTemplate postTemplate, IndexTemplate indexTemplate)
        {
            string dirPath  = Path.Combine(site.WebPath, p.Path);
            string htmlPath = Path.Combine(dirPath, "index.html");

            Directory.CreateDirectory(dirPath);
            if (Directory.Exists(p.SourceDir))
            {
                FileManager.Clone(p.SourceDir, dirPath);
            }

            var inst = indexTemplate.Create(site);

            inst["title"]    = p.Title;
            inst["author"]   = p.Author;
            inst["date"]     = p.Date.ToString("yyyy-MM-dd hh:mm:ss");
            inst["tabs"]     = GenerateTabs(site, null, p);
            inst["contents"] = postTemplate.Generate(site, p);
            inst["metatags"] = Html.Raw(p.MetaTags.ToHtml(inst));
            inst.Write(htmlPath);
        }
Exemple #21
0
        /// <summary>
        /// Creates a new post from the given template and return it
        /// as a edit model.
        /// </summary>
        /// <param name="templateId">The template id</param>
        /// <returns>The edit model</returns>
        public static EditModel CreateByTemplate(Guid templateId)
        {
            EditModel m = new EditModel();

            m.Permalink = new Permalink()
            {
                Id          = Guid.NewGuid(),
                Type        = Permalink.PermalinkType.POST,
                NamespaceId = Config.DefaultNamespaceId
            };
            m.Post = new Piranha.Models.Post()
            {
                Id          = Guid.NewGuid(),
                TemplateId  = templateId,
                PermalinkId = m.Permalink.Id
            };
            m.Template = PostTemplate.GetSingle(templateId);
            m.GetRelated();

            return(m);
        }
Exemple #22
0
        public async Task <PostTemplate <TUserPk> > CreateTemplateAsync(Post <TUserPk> content)
        {
            var template = new PostTemplate <TUserPk>
            {
                Title    = content.Title,
                AuthorId = content.AuthorId,
                Data     = new PostTemplateData {
                    Blocks = content.Blocks, Title = content.Title, Url = content.Url,
                },
                TagIds     = content.TagIds,
                SectionIds = content.SectionIds,
            };

            var result = await AddAsync(template);

            if (!result.IsSuccess)
            {
                throw new Exception(result.ErrorsString);
            }

            return(template);
        }
Exemple #23
0
        internal async void SendMessage(TelegramBotClient botClient, Message _message)
        {
            DataBase db   = Singleton.GetInstance().Context;
            User     user = db.GetUser(_message.From.Id); if (IsNullDataBase.IsNull(botClient, _message, user))
            {
                return;                                                                                                         // - заменить на другую таблицу
            }
            AdUser       adUser       = db.GetAdUser(user.ID);
            PostTemplate postTemplate = db.GetTempalte(adUser.User.ID, adUser.EditingPostTemplateId);

            try
            {
                AdController.SetContent(botClient, postTemplate, _message, 0);

                Int32 len = _message.Text.Length;

                if (len > 20)
                {
                    len = 20;
                }

                String str = new String(_message.Text.ToCharArray(), 0, len - 1);

                postTemplate.Name = _message.Text;
                await botClient.DeleteMessageAsync(_message.From.Id, _message.MessageId);

                await botClient.EditMessageTextAsync(_message.From.Id, user.MessageID, "Управление шаблоном\n1. Заполните контент\n2. Введите время постинга.\n3. Выберете чат(ы)\n4. Отправите на проверку администрации.", replyMarkup : InlineButton.ContentKeyboard(postTemplate, true));

                user.Chain = (System.Int32)SetChain.MessageUserInBot;
                db.Save();
            }
            catch (System.Exception ex)
            {
                Log.Logging(ex);
            }
            db.Save();
        }
        public static Single GetTotalPrice(PostTemplate template)
        {
            DataBase db         = Singleton.GetInstance().Context;
            Single   totalPrice = 0.0f;

            //totalPrice += GetPostTypePrice((TypePostTime)template.isPinnedMessage);

            foreach (PostChannel item in template.PostChannel)
            {
                if (item.Channel != null)
                {
                    totalPrice += StartSession.NumberOfParticipants(item.Channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
                else
                {
                    Channel channel = db.GetChannel(item.ChannelId);
                    totalPrice += StartSession.NumberOfParticipants(channel.InviteLink.Split("@")[1]) * (item.Channel.Price + GetPostTypePrice((TypePostTime)template.isPinnedMessage));
                }
            }

            foreach (PostTime item in template.PostTime)
            {
                if (item.Time != System.DateTime.Today)
                {
                    totalPrice += PriceData.postTypeTime;
                }
            }
            if ((totalPrice * 100) > 0)
            {
                return(totalPrice * 100);
            }
            else
            {
                return(100);
            }
        }
 public void Start(List <DateTime> calendar, PostTemplate post)
 {
     ChosesDates = new List <DateTime>();
     for (System.Int32 i = 0; i < calendar.Count; i++)
     {
         ChosesDates.Add(calendar[i]);
     }
     timeModels = new List <PostTime>();
     for (System.Int32 i = 0; i < ChosesDates.Count; i++)
     {
         if (post.PostTime.Count != 0 || ChosesDates.Count != 0)
         {
             if (post.PostTime.Any(p => p.Time.Year == ChosesDates[i].Year && p.Time.Day == ChosesDates[i].Day && p.Time.Month == ChosesDates[i].Month))
             {
                 timeModels = post.PostTime.ToList();
             }
         }
         else
         {
             timeModels = new List <PostTime>();
         }
     }
     PostTemplate = post;
 }
Exemple #26
0
 /// <summary>
 /// Default constructor. Creates a new model.
 /// </summary>
 public PostEditModel()
 {
     Template = new PostTemplate() ;
 }
 private Boolean GetPostTemplate(Int32 idPostTemplate)
 {
     adUser       = db.GetAdUser(user.ID);
     postTemplate = db.GetTempalte(adUser.User.ID, idPostTemplate);
     return(postTemplate == null);
 }
 private Boolean GetPostTemplate(Int32 idPostTemplate)
 {
     postTemplate = db.GetTempalte(user.ID, idPostTemplate);
     return(postTemplate == null);
 }
Exemple #29
0
 /// <summary>
 /// Default constructor. Creates a new model.
 /// </summary>
 public PostEditModel()
 {
     Template = new PostTemplate();
 }
Exemple #30
0
 /// <summary>
 /// Refreshes the current model.
 /// </summary>
 public void Refresh()
 {
     if (Post != null) {
         if (!Post.IsNew) {
             Post = Piranha.Models.Post.GetSingle(Post.Id, true) ;
             Permalink = Permalink.GetSingle(Post.PermalinkId) ;
             Category.GetByPostId(Post.Id).ForEach(c => PostCategories.Add(c.Id)) ;
             Categories = new MultiSelectList(Category.GetFields("category_id, category_name",
                 new Params() { OrderBy = "category_name" }), "Id", "Name", PostCategories) ;
         }
         Template = PostTemplate.GetSingle(Post.TemplateId) ;
         GetRelated() ;
     }
 }
Exemple #31
0
 public static PostTemplateModel ToModel(this PostTemplate entity)
 {
     return entity.MapTo<PostTemplate, PostTemplateModel>();
 }
Exemple #32
0
 public static PostTemplate ToEntity(this PostTemplateModel model, PostTemplate destination)
 {
     return model.MapTo(destination);
 }