public int Delete(ArticleFile fileData)
        {
            _dBtsicsContext.ArticleFile.Remove(fileData);
            var deleteFile = _dBtsicsContext.SaveChanges();

            return(deleteFile);
        }
Exemple #2
0
        public ActionResult Create(HttpPostedFileBase file, ArticleFileViewModel model)
        {
            try
            {
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var filePath = model.ArticleId.ToString() + "_" + fileName;
                    var path     = Path.Combine(Server.MapPath("~/Content/Upload"), filePath);
                    file.SaveAs(path);

                    ArticleFile articleView = new ArticleFile();
                    articleView.FileName  = fileName;
                    articleView.ArticleId = model.ArticleId;

                    var response = _articleFileLogic.Create(articleView);
                    if (response.IsError == true)
                    {
                        foreach (var item in response.ErrorCodes)
                        {
                            ModelState.AddModelError(string.Empty, item);
                        }
                        return(View(model));
                    }
                }

                return(RedirectToAction("Index", new { id = model.ArticleId }));
            }
            catch
            {
                return(View());
            }
        }
Exemple #3
0
        public ResponseMessage Create(ArticleFile entity)
        {
            ResponseMessage response = new ResponseMessage();

            _repository.Create(entity);

            return(response);
        }
Exemple #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            ArticleFile articleFile = db.ArticleFiles.Find(id);

            db.ArticleFiles.Remove(articleFile);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "id,ArticleId,file")] ArticleFile articleFile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(articleFile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ArticleId = new SelectList(db.articles, "id", "title", articleFile.ArticleId);
     return(View(articleFile));
 }
Exemple #6
0
        public ActionResult Edit(Article artikelObject, FormCollection collection)
        {
            if (Common.CheckAdmin())
            {
                return(RedirectToAction("Login", "Default"));
            }

            var articleEdit  = ParsingEdit(artikelObject, collection);
            var artikelModel = _literatureService.Edit(articleEdit);

            if (collection.AllKeys.Contains("tag-input[]"))
            {
                string tags = collection["tag-input[]"];
                UpdateArticleTags(tags, articleEdit.ArticleId);
            }
            //upload
            if (Request.Files.Count > 0)
            {
                if (Request.Files.AllKeys.Contains("attachment[]"))
                {
                    ArticleFile artikelFile     = Factory.Create <ArticleFile>("ArticleFile", ClassType.clsTypeDataModel);
                    int         attachmentIndex = 1;
                    string[]    fileLevel       = collection["file_level[]"].Split(',');
                    for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                    {
                        if (Request.Files.GetKey(i) == "attachment[]")
                        {
                            var    file       = Request.Files[i];
                            string response   = Common.ValidateFileUpload(file);
                            string dateString = DateTime.Now.ToString("yyyyMMddHmmss");
                            if (response.Equals("true"))
                            {
                                artikelFile.ArticleId = artikelModel.ArticleId;
                                artikelFile.Name      = Common.UploadFileArticle(file, Path.GetFileNameWithoutExtension(file.FileName) + "-" + artikelModel.ArticleId + "" + dateString + "-" + attachmentIndex);

                                artikelFile.LevelUser = fileLevel[i];
                                artikelFile.CreatedAt = DateTime.Now;

                                _articleFileBs.Add(artikelFile);
                                attachmentIndex += 1;
                            }
                        }
                    }
                }
            }
            if (collection["Submit"] == "Draft")
            {
                return(RedirectToAction("Draft"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Exemple #7
0
        // GET: ArticleFile/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArticleFile articleFile = db.ArticleFiles.Find(id);

            if (articleFile == null)
            {
                return(HttpNotFound());
            }
            return(View(articleFile));
        }
Exemple #8
0
        // GET: ArticleFile/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ArticleFile articleFile = db.ArticleFiles.Find(id);

            if (articleFile == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ArticleId = new SelectList(db.articles, "id", "title", articleFile.ArticleId);
            return(View(articleFile));
        }
Exemple #9
0
        public ActionResult Create([Bind(Include = "id,ArticleId,file")] ArticleFile articleFile, HttpPostedFileBase file)
        {
            articleFile.file = System.IO.Path.GetFileName(file.FileName);


            if (ModelState.IsValid)
            {
                db.ArticleFiles.Add(articleFile);
                db.SaveChanges();

                file.SaveAs(Server.MapPath("../uploads/articleFiles/" + articleFile.id.ToString() + articleFile.file));

                return(RedirectToAction("Index"));
            }

            ViewBag.ArticleId = new SelectList(db.articles, "id", "title", articleFile.ArticleId);
            return(View(articleFile));
        }
        public ArticleFile StringReader(string Filename, string Location)
        {
            ArticleFile newFile = new ArticleFile();
            newFile.Name = Filename;
            
            try
            {
                using (StreamReader sr = new StreamReader(Location + Filename, System.Text.Encoding.Default,true))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        newFile.AllLines.Add(line);
                    }
                }
                return newFile;
            }
            catch { return null; }

        }
 public ArticleFile Edit(ArticleFile entity)
 {
     throw new NotImplementedException();
 }
 public void Create(ArticleFile entity)
 {
     _db.ArticleFiles.Add(entity);
     _db.SaveChanges();
 }
Exemple #13
0
        public ActionResult LoadMore(int?page, int Category = 0, String keyword = "")
        {
            if (Session["userid"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (WebConfigure.GetLoginPortal() == "true" && Common.GetUserXupj().ToLower() != Session["username"].ToString().ToLower())
            {
                return(RedirectToAction("Login", "Account"));
            }

            ViewBag.Download     = WebConfigure.GetDomain() + "/Upload/Document/" + WebConfigure.GetUserGuideNameFileWithExtention();
            ViewBag.CategoryName = Category == 0 ? null : _articleCategoryBs.GetDetail(Category).Name;
            ViewBag.IconCategory = Category == 0 ? null : _articleCategoryBs.GetDetail(Category).Icon;

            ViewBag.UseFullLink = _articleBs.getUseFullLink().Count > 0 ? _articleBs.getUseFullLink() : null;
            List <Article> listArtikel = null;

            if (Category == 0)
            {
                listArtikel = _literatureService.GetListkeyword(keyword);
            }
            else
            {
                listArtikel = _literatureService.GetListbyCategory(Category, keyword);
            }
            #region Category
            ViewBag.Domain        = domain(isLocal);
            ViewBag.ListCategory1 = _articleCategoryBs.GetListCategoryMostUsedLiterature(0);
            #endregion

            List <ArticleFile>       ArticleData     = new List <ArticleFile>();
            List <CustomArticleTags> ArticleTagsData = new List <CustomArticleTags>();
            if (listArtikel != null)
            {
                foreach (var artikel in listArtikel)
                {
                    var FileData = _articleFileBs.GetListByArtikelId(artikel.ArticleId);
                    if (FileData != null)
                    {
                        foreach (var FileItem in FileData)
                        {
                            var fileCek = _articleFileBs.GetDetail(FileItem.ArticleId);
                            if (fileCek != null)
                            {
                                ArticleFile file = new ArticleFile()
                                {
                                    ArticleId = artikel.ArticleId,
                                    Name      = fileCek.Name,
                                };
                                ArticleData.Add(file);
                            }
                            var TagsData           = _articleTagsBs.GetTagsByArticle(artikel.ArticleId);
                            CustomArticleTags tags = new CustomArticleTags()
                            {
                                ArticleId = artikel.ArticleId,
                                Object    = TagsData.Count == 0 ? null : TagsData
                            };
                            ArticleTagsData.Add(tags);
                        }
                    }
                }
            }
            ViewBag.LiteratureTags = ArticleTagsData;
            ViewBag.LiteratureData = listArtikel;
            ViewBag.LiteratureItem = ArticleData;
            int pageSize   = 50;
            int pageNumber = (page ?? 1);
            return(View(listArtikel.ToPagedList(pageNumber, pageSize)));
        }
Exemple #14
0
 public ResponseMessage Edit(ArticleFile entity)
 {
     throw new NotImplementedException();
 }
        public ActionResult Edit(Article artikelObject, FormCollection collection)
        {
            ViewBag.UseFullLink = _articleBs.getUseFullLink().Count > 0 ? _articleBs.getUseFullLink() : null;
            if (WebConfigure.GetLoginPortal() == "true" && Common.GetUserXupj() != "" && Session["userid"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (Session["username"] != null)
            {
                if (WebConfigure.GetLoginPortal() == "true" && Common.GetUserXupj().ToLower() != Session["username"].ToString().ToLower())
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            if (!Common.CheckUserYellow())
            {
                return(RedirectToAction("Login", "Account"));
            }
            SetDropdownArtikelCategory(artikelObject);

            var artikelModel = ParsingEdit(artikelObject, collection);

            artikelModel = _articleBs.Edit(artikelModel);

            if (collection.AllKeys.Contains("tag-input[]"))
            {
                string tags = collection["tag-input[]"];
                UpdateArticleTags(tags, artikelModel.ArticleId);
            }
            //upload
            if (Request.Files.Count > 0)
            {
                for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                {
                    if (Request.Files.GetKey(i) == "header")
                    {
                        var    file     = Request.Files.Get(i);
                        string response = Common.ValidateFileUpload(file);

                        if (response.Equals("true"))
                        {
                            if (file != null)
                            {
                                var fileName = artikelModel.ArticleId + Path.GetExtension(file.FileName);

                                var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/Article/Header/"), fileName);

                                file.SaveAs(path);

                                artikelModel.HeaderImage = fileName;
                            }

                            _articleBs.Edit(artikelModel);
                        }
                    }
                }

                if (Request.Files.AllKeys.Contains("attachment[]"))
                {
                    _articleFileBs.DeleteAll(artikelModel.ArticleId);
                    ArticleFile artikelFile     = Factory.Create <ArticleFile>("ArticleFile", ClassType.clsTypeDataModel);
                    int         attachmentIndex = 1;
                    string[]    fileLevel       = collection["file_level[]"].Split(',');
                    for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                    {
                        if (Request.Files.GetKey(i) == "attachment[]")
                        {
                            var    file       = Request.Files[i];
                            string response   = Common.ValidateFileUpload(file);
                            string dateString = DateTime.Now.ToString("yyyyMMddHmmss");
                            if (response.Equals("true"))
                            {
                                artikelFile.ArticleId = artikelModel.ArticleId;
                                artikelFile.Name      = Common.UploadFileArticle(file, Path.GetFileNameWithoutExtension(file.FileName) + "-" + dateString + "-" + attachmentIndex);
                                artikelFile.LevelUser = fileLevel[i - 1];
                                artikelFile.CreatedAt = DateTime.Now;

                                _articleFileBs.Add(artikelFile);
                                attachmentIndex += 1;
                            }
                        }
                    }
                }
            }
            if (collection["type"] == "draft")
            {
                return(RedirectToAction("Draft", "Library"));
            }
            else
            {
                Email.SendMailPublishArticle(artikelModel);
                Email.SendMailNeedApp1Article(artikelModel);
                return(RedirectToAction("List", "Library"));
            }
        }
        public ActionResult Create(Article articleObject, FormCollection collection)
        {
            ViewBag.UseFullLink = _articleBs.getUseFullLink().Count > 0 ? _articleBs.getUseFullLink() : null;
            if (WebConfigure.GetLoginPortal() == "true" && Common.GetUserXupj() != "" && Session["userid"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            if (Session["username"] != null)
            {
                if (WebConfigure.GetLoginPortal() == "true" && Common.GetUserXupj().ToLower() != Session["username"].ToString().ToLower())
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            if (!Common.CheckUserYellow())
            {
                return(RedirectToAction("Login", "Account"));
            }

            articleObject.Position = 0;
            if (articleObject.Category1Id != 0)
            {
                articleObject.Category1 = _articleCategoryBs.GetDetail(articleObject.Category1Id).Name ?? "-";
            }
            if (articleObject.Category2Id != 0)
            {
                articleObject.Category2 = _articleCategoryBs.GetDetail(articleObject.Category2Id).Name ?? "-";
            }
            if (articleObject.Category3Id != 0)
            {
                articleObject.Category3 = _articleCategoryBs.GetDetail(articleObject.Category3Id).Name ?? "-";
            }
            if (articleObject.Category4Id != 0)
            {
                articleObject.Category4 = _articleCategoryBs.GetDetail(articleObject.Category4Id).Name ?? "-";
            }
            if (articleObject.Category5Id != 0)
            {
                articleObject.Category5 = _articleCategoryBs.GetDetail(articleObject.Category5Id).Name ?? "-";
            }
            if (articleObject.Category6Id != 0)
            {
                articleObject.Category6 = _articleCategoryBs.GetDetail(articleObject.Category6Id).Name ?? "-";
            }
            if (articleObject.Category7Id != 0)
            {
                articleObject.Category7 = _articleCategoryBs.GetDetail(articleObject.Category7Id).Name ?? "-";
            }

            articleObject.CreatedAt = DateTime.Now;
            if (collection["type"] == "draft")
            {
                articleObject.Status = 2;
            }
            else
            {
                articleObject.Status = 0;
            }
            articleObject.CreatedBy = Convert.ToInt32(Session["userid"]);

            String token = Common.AccessToken() + DateTime.Now.ToString("ddMMyyyy");

            token = token.Replace("/", "");
            token = token.Replace("+", "");
            articleObject.Token = token;
            var articleModel = _articleBs.Add(articleObject);

            if (Request.Files.Count > 0)
            {
                //ArticleFile articleFile = Factory.Create<ArticleFile>("ArticleFile", ClassType.clsTypeDataModel);

                //for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                //{
                //    var file = Request.Files[i];
                //    string response = Common.ValidateFileUpload(file);

                //    if (response.Equals("true"))
                //    {
                //        articleFile.ArticleId = articleModel.ArticleId;
                //        articleFile.Name = Common.UploadFileArticle(file, articleModel.ArticleId + "-" + i.ToString());
                //        articleFile.CreatedAt = DateTime.Now;

                //        _articleFileBs.Add(articleFile);
                //    }
                //}
                for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                {
                    if (Request.Files.GetKey(i) == "header")
                    {
                        var    file     = Request.Files.Get(i);
                        string response = Common.ValidateFileUpload(file);

                        if (response.Equals("true"))
                        {
                            if (file != null)
                            {
                                var fileName = articleModel.ArticleId + Path.GetExtension(file.FileName);

                                var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/Article/Header/"), fileName);

                                file.SaveAs(path);

                                articleModel.HeaderImage = fileName;
                            }

                            _articleBs.Edit(articleModel);
                        }
                    }
                }
                if (Request.Files.AllKeys.Contains("attachment[]"))
                {
                    ArticleFile artikelFile     = Factory.Create <ArticleFile>("ArticleFile", ClassType.clsTypeDataModel);
                    int         attachmentIndex = 1;
                    string[]    fileLevel       = collection["file_level[]"].Split(',');
                    for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                    {
                        if (Request.Files.GetKey(i) == "attachment[]")
                        {
                            var    file       = Request.Files[i];
                            string response   = Common.ValidateFileUpload(file);
                            string dateString = DateTime.Now.ToString("yyyyMMddHmmss");
                            if (response.Equals("true"))
                            {
                                artikelFile.ArticleId = articleModel.ArticleId;
                                artikelFile.Name      = Common.UploadFileArticle(file, Path.GetFileNameWithoutExtension(file.FileName) + "-" + dateString + "-" + attachmentIndex);
                                artikelFile.LevelUser = fileLevel[i - 1];
                                artikelFile.CreatedAt = DateTime.Now;

                                _articleFileBs.Add(artikelFile);
                                attachmentIndex += 1;
                            }
                        }
                    }
                }
            }
            if (collection["type"] == "draft")
            {
                return(RedirectToAction("Draft", "Library"));
            }
            else
            {
                Email.SendMailPublishArticle(articleModel);
                Email.SendMailNeedApp1Article(articleModel);
                return(RedirectToAction("List", "Library"));
            }
        }
Exemple #17
0
        public ActionResult Edit(Article artikelObject, FormCollection collection)
        {
            if (Common.CheckAdmin())
            {
                return(RedirectToAction("Login", "Default"));
            }

            SetDropdownArtikelCategory(artikelObject);

            var artikelModel = ParsingEdit(artikelObject, collection);

            artikelModel = _articleService.Edit(artikelModel);

            if (collection.AllKeys.Contains("tag-input[]"))
            {
                string tags = collection["tag-input[]"];
                UpdateArticleTags(tags, artikelModel.ArticleId);
            }
            //upload
            if (Request.Files.Count > 0)
            {
                for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                {
                    if (Request.Files.GetKey(i) == "header")
                    {
                        var    file     = Request.Files.Get(i);
                        string response = Common.ValidateFileUpload(file);

                        if (response.Equals("true"))
                        {
                            if (file != null)
                            {
                                var fileName = artikelModel.ArticleId + Path.GetExtension(file.FileName);

                                var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload/Article/Header/"), fileName);

                                file.SaveAs(path);

                                artikelModel.HeaderImage = fileName;
                            }

                            _articleService.Edit(artikelModel);
                        }
                    }
                }

                if (Request.Files.AllKeys.Contains("attachment[]"))
                {
                    ArticleFile artikelFile     = Factory.Create <ArticleFile>("ArticleFile", ClassType.clsTypeDataModel);
                    int         attachmentIndex = 1;
                    string[]    fileLevel       = collection["file_level[]"].Split(',');
                    for (int i = 0, iLen = Request.Files.Count; i < iLen; i++)
                    {
                        if (Request.Files.GetKey(i) == "attachment[]")
                        {
                            var    file       = Request.Files[i];
                            string response   = Common.ValidateFileUpload(file);
                            string dateString = DateTime.Now.ToString("yyyyMMddHmmss");
                            if (response.Equals("true"))
                            {
                                artikelFile.ArticleId = artikelModel.ArticleId;
                                artikelFile.Name      = Common.UploadFileArticle(file, Path.GetFileNameWithoutExtension(file.FileName) + "-" + dateString + "-" + attachmentIndex);
                                artikelFile.LevelUser = fileLevel[i - 1];
                                artikelFile.CreatedAt = DateTime.Now;

                                _articleFileBs.Add(artikelFile);
                                attachmentIndex += 1;
                            }
                        }
                    }
                }
            }
            if (artikelObject.Status == 9 && artikelModel.Status == 1)
            {
                Email.SendMailSubmitedArticle(artikelModel, _UserBService.GetDetail(artikelObject.CreatedBy));
            }
            if (collection["type"].Contains("draft"))
            {
                return(RedirectToAction("Draft"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
 public ArticleFile Add(ArticleFile article)
 {
     _dBtsicsContext.ArticleFile.Add(article);
     _dBtsicsContext.SaveChanges();
     return(article);
 }