예제 #1
0
 /// <summary>
 /// Create a new Article object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="text">Initial value of the Text property.</param>
 /// <param name="postedAt">Initial value of the PostedAt property.</param>
 /// <param name="accountId">Initial value of the AccountId property.</param>
 /// <param name="fileId">Initial value of the FileId property.</param>
 public static Article CreateArticle(global::System.Int32 id, global::System.String title, global::System.String text, global::System.DateTime postedAt, global::System.Int32 accountId, global::System.Int32 fileId)
 {
     Article article = new Article();
     article.Id = id;
     article.Title = title;
     article.Text = text;
     article.PostedAt = postedAt;
     article.AccountId = accountId;
     article.FileId = fileId;
     return article;
 }
예제 #2
0
        public ActionResult AddNew(AddArticleViewModel avm, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                using (new UnitOfWork(_currentContext))
                {
                    //upload file first
                    var ticks = DateTime.Now.Ticks;
                    var fileName = String.Format("article-{0}", ticks) + Path.GetExtension(file.FileName);
                    var absoluteTempPath = Server.MapPath("~/Content/images/uploads/temp/");
                    var absolutePath = Server.MapPath("~/Content/images/uploads/news/");
                    var fullVirtualPath = "~/Content/images/uploads/news/" + fileName;
                    //create a temp file first, then compress it
                    FileUploader.UploadFile(file, fileName,
                                            absoluteTempPath);

                    var encoder = new ImageEncoder();
                    encoder.Compress(absoluteTempPath + fileName, absolutePath + fileName, 620, 465);
                    //after compressing deleting original file
                    FileUploader.DeleteFile(absoluteTempPath + fileName);

                    var articleImage = new File()
                    {
                        FileName = fullVirtualPath,
                        FilePurposeId = (int)FilePurposes.Slideshow
                    };

                    var article = new Article()
                                      {
                                          Account = accountRepository.GetByUsername(CurrentUserName),
                                          Title = avm.Title,
                                          Text = avm.Text,
                                          PostedAt = DateTime.Now,
                                          File = articleImage
                                      };

                    articlesRepository.Add(article);
                }

                TempData[Const.ActionResultInfo] = "Статья успешно добавлена";
                return RedirectToAction("News");
            }

            TempData[Const.ActionErrorInfo] = "Невозможно добавить статью, проверьте корректность введенных данных";
            return View();
        }
예제 #3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ArticleSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToArticleSet(Article article)
 {
     base.AddObject("ArticleSet", article);
 }