Example #1
0
        public IActionResult Create([Bind("ArticleId,Title,Url,Abstract,Contents,CreatedDate,AuthorId,MainImagePath,AuthorName")] Article article)
        {
            if (ModelState.IsValid)
            {
                article.AuthorId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
                article.CreatedDate = DateTime.Now;
                article.InActive    = true;
                _repo.Add(article);

                return(RedirectToAction("BlogList", "Admin"));
            }
            //ViewData["AuthorId"] = new SelectList(_context.Users, "Id", "Id", article.AuthorId);
            return(View(article));
        }
Example #2
0
        public IHttpActionResult Create(string id, string name, string content)
        {
            var exists = ArticlesRepository.Get(id) != null;


            if (exists)
            {
                return(StatusCode(HttpStatusCode.Conflict));
            }
            else
            {
                ArticlesRepository.Add(id, name, content);
                return(Ok());
            }
        }
Example #3
0
        public ControllerResult Add(AddArticleModel addmodel)
        {
            try
            {
                var userBlogs = blogsRepository.GetSortedUserBlogs(addmodel.UserName).Blogs.ToArray();
                var blogId    = userBlogs[addmodel.BlogNumber].Id;

                Article article = new Article(addmodel.Name, addmodel.Text, addmodel.Tags.ToList(), blogId, addmodel.Likes, addmodel.Views, addmodel.Comments.ToList());

                articlesRepository.Add(article);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
Example #4
0
        public async Task <IActionResult> Create(Article model)
        {
            model.AddedDate = DateTime.Now;
            var result = await _repo.Add(model);

            if (result == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response <Article>()
                {
                    Succeeded = false, Message = "ثبت مقاله= با مشکل مواجه شد لطفا ورودی های خود را چک کرده و مجددا تلاش کنید"
                }));
            }


            return(Ok(new Response <Article>(result)
            {
                Message = "مقاله با موفقیت ثبت شد"
            }));
        }
Example #5
0
        public ActionResult Create(ArticlesModel article)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ArticlesRepository ArticleRepo = new ArticlesRepository();
                    ArticleRepo.Add(article);
                    ViewBag.Message = "Your Article has been published";
                }
                // TODO: Add insert logic here

                return(RedirectToAction("Create"));
            }
            catch
            {
                return(View());
            }
        }
        public void SaveToDb()
        {
            db     = new ContentManagementEntities();
            rep    = new ArticlesRepository();
            entity = new Articles();
            id     = Convert.ToInt32(Request.QueryString["id"]);
            if (id != 0)
            {
                myid = id;
            }
            entity.Authors     = db.Authors.Where(c => c.Id == myid).FirstOrDefault();
            entity.AuthorId    = entity.Authors.Id;
            entity.ArticleBody = Request.Form["ArticleBody"];
            entity.Title       = Request.Form["Title"];
            int catId = Convert.ToInt32(Request.Form["CatType"]);

            entity.Categories = db.Categories.Where(c => c.Id == catId).FirstOrDefault();
            entity.CreateDate = DateTime.Now;
            entity.CategoryId = entity.Categories.Id;
            entity.IsVisible  = true;

            rep.Add(entity, db);
            Response.Redirect("/ReadArticlesPage");
        }
Example #7
0
        static void Main(string[] args)
        {
            DoMigration();

            while (true)
            {
                Console.WriteLine("1. Добавить статью\n2.Добавить комментарий\n3.Показать новости\n4.Выход");
                Console.Write("Выберите действие: ");

                if (!int.TryParse(Console.ReadLine(), out int action))
                {
                    Console.WriteLine("Ошибка! Введите цифры!");
                }
                else if (action < 0 || action > 5)
                {
                    Console.WriteLine("Не существует такого действия!");
                }

                if (action == 1)
                {
                    var article = InitArticle();

                    using (var articleRepository = new ArticlesRepository(connectionString))
                    {
                        articleRepository.Add(article);

                        Console.WriteLine("Статья успешно добавлена!");
                    }
                }
                else if (action == 2)
                {
                    var comment = InitComment();

                    using (var commentRepository = new CommentsRepository(connectionString))
                    {
                        commentRepository.Add(comment);

                        Console.WriteLine("Коммент успешно добавлен!");
                    }
                }
                else if (action == 3)
                {
                    List <Article> articles;

                    using (var articlesRepository = new ArticlesRepository(connectionString))
                    {
                        articles = articlesRepository.GetAll().ToList();
                    }

                    foreach (var article in articles)
                    {
                        Console.WriteLine($"{article.Name}");
                    }
                }
                else if (action == 4)
                {
                    break;
                }

                Console.ReadLine();
                Console.Clear();
            }
        }