コード例 #1
0
        public static void SetItem(ArticleModels item, int cardStyleID = 1)
        {
            SQLData.Database    db       = new SQLData.Database(WebInfo.Conn);
            SQLData.TableObject tableObj = db.GetTableObject("Article");
            tableObj.GetDataFromObject(item);
            string sql   = "Select 1 From Article Where ID = " + item.ID;
            bool   isNew = db.GetFirstValue(sql) == null;

            if (isNew)
            {
                MenusModels menu   = MenusDAO.GetInfo(item.SiteID, item.MenuID);
                long        cardNo = WorkV3.Golbal.PubFunc.AddPage(item.SiteID, item.MenuID, menu.SN, "Article", "Content", true, item.Title, CardStyleId: cardStyleID);
                tableObj["CardNo"]     = cardNo;
                tableObj["Creator"]    = MemberDAO.SysCurrent.Id;
                tableObj["CreateTime"] = DateTime.Now;
                tableObj["Sort"]       = 1;

                tableObj.Insert();
            }
            else
            {
                tableObj.Remove("ID");
                tableObj.Remove("SiteID");
                tableObj.Remove("MenuID");
                tableObj.Remove("CardNo");
                tableObj.Remove("Clicks");
                tableObj.Remove("Creator");
                tableObj.Remove("CreateTime");

                tableObj["Modifier"]   = MemberDAO.SysCurrent.Id;
                tableObj["ModifyTime"] = DateTime.Now;

                tableObj.Update(item.ID);
            }
        }
コード例 #2
0
        public static ArticleModels JsonToArticleModel(IEnumerable <ArticleModels> article, bool isDetail)
        {
            ArticleModels temp = null;

            if (article == null)
            {
            }
            else
            {
                //foreach (var x in article)
                //{
                temp = new ArticleModels()
                {
                    Description = article.FirstOrDefault().Description,
                    Author      = article.FirstOrDefault().Author,
                    //ID = article.FirstOrDefault().ID,
                    PublishedAt = article.FirstOrDefault().PublishedAt,
                    Title       = article.FirstOrDefault().Title,
                    Source      = article.FirstOrDefault().Source,
                    URL         = article.FirstOrDefault().URL,
                    URLToImage  = article.FirstOrDefault().URLToImage
                };
            }
            return(temp);
        }
コード例 #3
0
        public async Task <IHttpActionResult> PutArticleModels(int id, ArticleModels articleModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != articleModels.Id)
            {
                return(BadRequest());
            }

            try
            {
                await new ArticleModelsBLL().SaveArticleModels(articleModels);
            }
            catch (IndexOutOfRangeException ex)
            {
                // Logging would go here
                return(BadRequest());
            }
            catch (ArgumentOutOfRangeException ex)
            {
                // Logging would go here
                return(BadRequest());
            }

            catch (Exception ex)
            {
                // Logging would go here
                return(InternalServerError());
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        public void Copy(long siteId, long menuId, long[] ArticleIds, long TargetMenuID)
        {
            ViewBag.SiteID     = siteId;
            ViewBag.MenuID     = menuId;
            ViewBag.ActionType = "copy";
            if (ArticleIds.Length == 0)
            {
                return;
            }

            var targetMenu = MenusDAO.GetInfo(TargetMenuID);

            foreach (long ArticleId in ArticleIds)
            {
                ArticleModels articleItem = ArticleDAO.GetItem(ArticleId);
                CardsModels   cardItem    = CardsDAO.GetByNo(articleItem.CardNo);
                ZonesModels   zoneItem    = ZonesDAO.GetByNo(cardItem.ZoneNo.Value);
                PagesModels   pageItem    = PagesDAO.GetPageInfo(zoneItem.PageNo);

                long newCardNo       = WorkV3.Golbal.PubFunc.CopyPage(pageItem, targetMenu.SiteID, targetMenu.ID);
                long newArticleId    = WorkLib.GetItem.NewSN();
                bool IsForceRelative = false;
                if (pageItem.SiteID == targetMenu.SiteID && pageItem.MenuID == targetMenu.ID)
                {
                    IsForceRelative = true;
                }
                ArticleDAO.CopyArticle(ArticleId, newArticleId, newCardNo, targetMenu.ID, targetMenu.SiteID, IsForceRelative);
                WorkV3.Golbal.PubFunc.CopyIcon(articleItem.Icon, siteId, menuId, targetMenu.SiteID, targetMenu.ID);
                WorkV3.Golbal.PubFunc.CopyParagraphPhotos(articleItem.ID, siteId, menuId, targetMenu.SiteID, targetMenu.ID);
            }
        }
コード例 #5
0
        /// <summary>
        /// Home Page (Master view) of the app. Returns a list of articles from the NEWS API.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string sortOrder, string filterByDate, string filterByLevel)
        {
            Rootobject root = new Rootobject();

            using (var webClient = new System.Net.WebClient())
            {
                //Specified encoding to avoid issues related to German language characters
                webClient.Encoding = Encoding.UTF8;

                var json = webClient.DownloadString(ENDPOINT);

                //Not directly deserialized to Rootobject as the JSON is in the [{}] form.
                root.articles = JsonConvert.DeserializeObject <List <JsonArticle> >(json);
            }

            List <ArticleModels> articleList = new List <ArticleModels>();


            foreach (JsonArticle article in root.articles)
            {
                ArticleModels temp = Helpers.JsonToArticleModel(article, false);
                articleList.Add(temp);
            }

            switch (sortOrder)
            {
            case "level":
                articleList = articleList.OrderByDescending(s => s.level).ToList();
                break;

            case "title":
                articleList = articleList.OrderBy(s => s.title).ToList();     //Assending Order for titles.
                break;

            case "date":
                articleList = articleList.OrderByDescending(s => s.published_date).ToList();
                break;

            default:
                articleList = articleList.OrderByDescending(s => s.id).ToList();
                break;
            }

            if (!String.IsNullOrEmpty(filterByDate))
            {
                DateTime date;
                if (DateTime.TryParse(filterByDate, out date)) //Avoid invalid DateTimeInput
                //  articleList = articleList.Where(x => x.published_date==date).ToList(); //TODO: "Contains" for DateTime Comparision
                {
                    articleList = articleList.Where(x => x.published_date.ToString().Contains(filterByDate)).ToList(); //TODO: Unuglify
                }
            }
            if (!String.IsNullOrEmpty(filterByLevel))
            {
                articleList = articleList.Where(x => x.level.Equals(filterByLevel)).ToList();
            }

            return(View(articleList));
        }
コード例 #6
0
        public async Task SaveArticleModels(ArticleModels articleModels)
        {
            if (articleModels.Id <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            await new ArticleModelsDAL().SaveArticleModels(articleModels);
        }
コード例 #7
0
        public static List <ArticleModels> GetItems(ArticleSettingModels setting, string key, string type, long?typeId, int pageIndex, out int totalRecord)
        {
            SQLData.Database db = new SQLData.Database(WebInfo.Conn);

            //string sessionKey = setting.MenuID.ToString();
            //string token = key + type + typeId;
            //System.Web.SessionState.HttpSessionState session = HttpContext.Current.Session;

            //dynamic sessionVal = session[sessionKey];
            List <long> ids = null;
            //if(sessionVal == null || sessionVal.Token != token) {
            //    session.Remove(sessionKey);

            string query = $"Select ID From Article A Where { GetWhereSql(setting, key, type, typeId) } Order By { setting.SortField }";

            ids = db.GetDataTable(query).AsEnumerable().Select(dr => (long)dr["ID"]).ToList();

            //    session.Add(sessionKey, new { Token = token, IDList = ids });
            //} else {
            //    ids = sessionVal.IDList;
            //}

            if (ids == null)
            {
                ids = new List <long>();
            }

            totalRecord = ids.Count;

            IEnumerable <long> currentIds = ids.Skip((pageIndex - 1) * setting.PageSize).Take(setting.PageSize);

            if (currentIds.Count() == 0)
            {
                return(new List <ArticleModels>());
            }

            string sql =
                "Select ID,SiteID, CardNo, Type, Title, Link, IsOpenNew, Archive, IssueDate, CustomIcon, Icon, IsShowVideo, VideoID, " +
                "(SELECT TOP(1) Contents FROM Paragraph WHERE SourceNo = A.ID AND Contents <> '' ORDER BY Sort) Summary " +
                $"From Article A Where ID IN ({ string.Join(", ", currentIds) })";
            DataTable datas = db.GetDataTable(sql);

            List <ArticleModels> items    = GetListItems(datas);
            List <ArticleModels> itemList = new List <ArticleModels>();

            foreach (long id in currentIds)
            {
                ArticleModels item = items.FirstOrDefault(a => a.ID == id);
                if (item != null)
                {
                    itemList.Add(item);
                }
            }

            return(itemList);
        }
コード例 #8
0
 public ActionResult New(ArticleModels art)
 {
     art.CategoryId = 8;
     if (TryUpdateModel(art))
     {
         context.Articles.Add(art);
         context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #9
0
        public ActionResult New()
        {
            var viewModel = new ArticleModels
            {
                ArticleDate = DateTime.Now
            }
            ;

            return(View(viewModel));
        }
コード例 #10
0
ファイル: PagesDAO.cs プロジェクト: jim-deng-git/Ask
        public static string GetContentDesc(long SiteID, long MenuID, long PageNo)
        {
            List <ZonesModels> zoneList     = ZonesDAO.GetPageData(SiteID, PageNo);
            string             newUploadUrl = WorkV3.Golbal.UpdFileInfo.GetVPathByMenuID(SiteID, MenuID).TrimEnd('/') + "/";

            if (zoneList != null && zoneList.Count > 0)
            {
                for (int i = 0; i < zoneList.Count; i++)
                {
                    List <CardsModels> cardList = CardsDAO.GetZoneData(SiteID, zoneList[i].No);
                    if (cardList != null && cardList.Count > 0)
                    {
                        switch (cardList[0].CardsType)
                        {
                        case "Article":
                            ArticleModels articleModel = ArticleDAO.GetItemByCard(cardList[0].No);
                            if (articleModel != null)
                            {
                                var paragraphs = ParagraphDAO.GetItems(articleModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            return(paragraph.Contents.TrimTags().Truncate(100));
                                        }
                                    }
                                }
                            }
                            break;

                        case "ArticleIntro":
                            ArticleIntroModels articleIntroModel = ArticleIntroDAO.GetItem(cardList[0].No);
                            if (articleIntroModel != null)
                            {
                                var paragraphs = ParagraphDAO.GetItems(articleIntroModel.ID);
                                if (paragraphs != null && paragraphs.Count() > 0)
                                {
                                    foreach (ParagraphModels paragraph in paragraphs)
                                    {
                                        if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                                        {
                                            return(paragraph.Contents.TrimTags().Truncate(100));
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return("");
        }
コード例 #11
0
        public async Task <ArticleModels> DeleteArticleModels(int id)
        {
            ArticleModels existingArticleModels = await ProbeProblemDatabase.Instance.ArticleDB.FindAsync(id);

            if (existingArticleModels == null)
            {
                throw new ArgumentOutOfRangeException();
            }
            await new ArticleModelsDAL().DeleteArticleModels(existingArticleModels);
            return(existingArticleModels);
        }
コード例 #12
0
        public ActionResult Create()
        {
            ICategoryService artCateSrv = IoC.Resolve <ICategoryService>();
            ArticleModels    model      = new ArticleModels();

            model.Article           = new Articles();
            model.Article.StartDate = DateTime.Now;
            model.Article.EndDate   = DateTime.Now;
            model.Categories        = artCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
            return(View(model));
        }
コード例 #13
0
        public ActionResult ViewDetails(string title)
        {
            using (var webClient = new System.Net.WebClient())
            {
                var json = webClient.DownloadString(url);
                var root = JsonConvert.DeserializeObject <JsonModels>(json).Articles.Where(x => x.Title == title);

                ArticleModels temp = Helpers.JsonToArticleModel(root, true);

                return(PartialView("_ArticlePartial", temp));
            }
        }
コード例 #14
0
        public bool GetArticleForRead(out ArticleModels articleData, int ID)
        {
            //var context = new SiteContext();
            articleData = context.Articles.Find(ID);

            if (articleData.status == ArticleModels.Status.Failed)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #15
0
ファイル: ArticleController.cs プロジェクト: IMEDHK/tuto1
        public ActionResult Article(ArticleModels model)
        {
            //  var model = new ArticleModels
            //{
            //  ID = id,
            //TITLE = title

            //    };

            //title = !string.IsNullOrEmpty(title) ? ViewBag.ArticleTitle = title.Replace('-', ' ') : ViewBag.ArticleTitle = title.Replace('-', ' ');


            return(View(model));
        }
コード例 #16
0
        public ActionResult Update(int id, HttpPostedFileBase dataFile, bool isEn = false)
        {
            IArticlesService artSrv = IoC.Resolve <IArticlesService>();
            Articles         art    = artSrv.Getbykey(id);

            try
            {
                TryUpdateModel <Articles>(art);
                art.ModifiedBy   = HttpContext.User.Identity.Name;
                art.ModifiedDate = DateTime.Now;
                art.URLName      = FX.Utils.Common.TextHelper.ToUrlFriendly(art.NameVNI);
                if (!art.IsEvent)
                {
                    art.StartDate = DateTime.Now;
                    art.EndDate   = DateTime.Now;
                }
                if (dataFile != null && dataFile.ContentLength > 0)
                {
                    art.TypeData = dataFile.FileName.Substring(dataFile.FileName.LastIndexOf("."));
                    byte[] bf = new byte[dataFile.ContentLength];
                    dataFile.InputStream.Read(bf, 0, dataFile.ContentLength);
                    art.AttachData = bf;
                }
                artSrv.Update(art);
                artSrv.CommitChanges();
                Messages.AddFlashMessage("Cập nhật thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - Edit:" + art.Id, "Edit complete", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);

                if (isEn)
                {
                    return(View("Indexen"));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - Edit:" + art.Id, "Edit error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                ICategoryService artCateSrv = IoC.Resolve <ICategoryService>();
                ArticleModels    model      = new ArticleModels();
                model.Article    = artSrv.Getbykey(id);
                model.Categories = artCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
                if (isEn)
                {
                    return(View("Editen", model));
                }
                return(View("Edit", model));
            }
        }
コード例 #17
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        private void SaveIconAndArchive(long siteId, long menuId, ArticleModels item)
        {
            if (!string.IsNullOrWhiteSpace(item.Icon))
            {
                ResourceImagesModels imgModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(item.Icon);
                if (imgModel.ID == 0)   // 新上傳的圖片
                {
                    HttpPostedFileBase postedFile              = Request.Files["fIcon"];
                    string             postedFileBase64        = Request.Form["fIconBase64"];
                    string             postedFileBase64_Resize = Request.Form["fIconBase64_Resize"];
                    if (postedFile == null || postedFile.ContentLength == 0)
                    {
                        item.Icon = string.Empty;
                    }
                    else
                    {
                        string saveName = WorkV3.Golbal.UpdFileInfo.SaveFilesByMenuID(postedFile, siteId, menuId, postedFileBase64, postedFileBase64_Resize);
                        imgModel.ID  = 1;
                        imgModel.Img = saveName;

                        item.Icon = Newtonsoft.Json.JsonConvert.SerializeObject(imgModel);
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(item.Archive))
            {
                ResourceFilesModels archiveModel = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceFilesModels>(item.Archive);
                if (archiveModel.Id == 0)
                {
                    HttpPostedFileBase postedFile = Request.Files["fArchive"];
                    if (postedFile == null || postedFile.ContentLength == 0)
                    {
                        item.Icon = string.Empty;
                    }
                    else
                    {
                        string saveName = WorkV3.Golbal.UpdFileInfo.SaveFilesByMenuID(postedFile, siteId, menuId);
                        archiveModel.Id       = 1;
                        archiveModel.FileInfo = saveName;
                        archiveModel.FileSize = postedFile.ContentLength;

                        item.Archive = Newtonsoft.Json.JsonConvert.SerializeObject(archiveModel);
                    }
                }
            }
        }
コード例 #18
0
 public async Task <IHttpActionResult> GetArticleModels(int id)
 {
     try
     {
         ArticleModels articleModels = await new ArticleModelsBLL().GetArticleModelsById(id);
         if (articleModels == null)
         {
             return(NotFound());
         }
         return(Ok(articleModels));
     }
     catch (Exception ex)
     {
         // Logging would go here
         return(InternalServerError());
     }
 }
コード例 #19
0
ファイル: Helpers.cs プロジェクト: galstyankaren/NewsApp
        /// <summary>
        /// Converts Json model to Article model.
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public static ArticleModels JsonToArticleModel(JsonArticle article, bool isDetail)
        {
            string[] articlesList = article.body.Split('.');

            ArticleModels temp = new ArticleModels()
            {
                body            = (isDetail)? article.body : String.Format(articlesList[0] + "." + articlesList[1] + "..."), //Checks if the model is going to view or not for body text stripping.
                categories      = article.categories,
                id              = article.id,
                level           = LevelToCategory(article.level),
                url_action      = article.url_action,
                published_date  = Helpers.UnixToDateTime(article.published_date), //Converts Unix TimeStamp to DateTime
                title           = article.title,
                url_explanation = article.url_explanation
            };

            return(temp);
        }
コード例 #20
0
 public async Task <IHttpActionResult> DeleteArticleModels(int id)
 {
     try
     {
         ArticleModels articleModels = await new ArticleModelsBLL().DeleteArticleModels(id);
         return(Ok(articleModels));
     }
     catch (ArgumentOutOfRangeException ex)
     {
         // Logging here
         return(NotFound());
     }
     catch (Exception ex)
     {
         // logging here
         return(InternalServerError());
     }
 }
コード例 #21
0
        public async Task <IHttpActionResult> PostArticleModels(ArticleModels articleModels)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                await new ArticleModelsBLL().CreateArticleModels(articleModels);
            }
            catch (Exception ex)
            {
                // Logging would go here
                return(InternalServerError());
            }
            return(CreatedAtRoute("DefaultApi", new { id = articleModels.Id }, articleModels));
        }
コード例 #22
0
        public ActionResult Create(Articles art, HttpPostedFileBase dataFile)
        {
            try
            {
                IArticlesService artSrv = IoC.Resolve <IArticlesService>();
                art.CreatedBy = HttpContext.User.Identity.Name;
                art.URLName   = FX.Utils.Common.TextHelper.ToUrlFriendly(art.NameVNI);
                if (!art.IsEvent)
                {
                    art.StartDate = DateTime.Now;
                    art.EndDate   = DateTime.Now;
                }
                if (dataFile != null && dataFile.ContentLength > 0)
                {
                    art.TypeData = dataFile.FileName.Substring(dataFile.FileName.LastIndexOf("."));
                    byte[] bf = new byte[dataFile.ContentLength];
                    dataFile.InputStream.Read(bf, 0, dataFile.ContentLength);
                    art.AttachData = bf;
                }
                artSrv.CreateNew(art);
                // tu động approved
                art.Approved  = true;
                art.ApproveBy = HttpContext.User.Identity.Name;
                art.Active    = true;

                artSrv.CommitChanges();
                Messages.AddFlashMessage("Thêm mới thành công.");

                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - Create:" + art.Id, "Create Article complete", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - Create:" + art.Id, "Create Error" + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                ICategoryService artCateSrv = IoC.Resolve <ICategoryService>();
                ArticleModels    model      = new ArticleModels();
                model.Article = art;

                model.Categories = artCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
                return(View(model));
            }
        }
コード例 #23
0
        public ActionResult Edit(int id, ArticleModels requestArt)
        {
            var art = context.Articles.SingleOrDefault(m => m.Id == id);

            if (art == null)
            {
                return(HttpNotFound());
            }
            if (TryUpdateModel(art))
            {
                art.ArticleDate        = requestArt.ArticleDate;
                art.ArticleDescription = requestArt.ArticleDescription;
                art.ArticleName        = requestArt.ArticleName;
                art.ArticleText        = requestArt.ArticleText;
                art.AuthorName         = requestArt.AuthorName;
                context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #24
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        private static void SaveParagraph(ArticleModels item, IEnumerable <ParagraphModels> paragraphs, string deletedParagraphs)
        {
            //WorkLib.WriteLog.Write(true, paragraphs.Count().ToString());
            if (paragraphs != null && paragraphs.Count() > 0)
            {
                for (int i = 0, len = paragraphs.Count(); i < len; ++i)
                {
                    ParagraphModels p = paragraphs.ElementAt(i);
                    p.Sort     = (byte)i;
                    p.SourceNo = item.ID;
                    ParagraphDAO.SetItem(p);
                }
            }

            if (!string.IsNullOrWhiteSpace(deletedParagraphs))
            {
                IEnumerable <long> delParagraphIds = deletedParagraphs.Split(',').Select(p => long.Parse(p));
                ParagraphDAO.Delete(delParagraphIds);
            }
        }
コード例 #25
0
        public ActionResult Edit(int id, bool isEn = false)
        {
            IArticlesService artSrv     = IoC.Resolve <IArticlesService>();
            ICategoryService artCateSrv = IoC.Resolve <ICategoryService>();
            var art = artSrv.Getbykey(id);

            if (art == null)
            {
                Messages.AddErrorFlashMessage("Bài viết không tồn tại hoặc đã bị xóa");
                return(RedirectToAction("Index", new { isEn = isEn }));
            }
            ArticleModels model = new ArticleModels();

            model.Article    = art;
            model.Categories = artCateSrv.Query.Where(p => p.Active).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
            if (isEn)
            {
                return(View("Editen", model));
            }
            return(View(model));
        }
コード例 #26
0
        public async Task SaveArticleModels(ArticleModels articleModels)
        {
            ProbeProblemDatabase.Instance.Entry(articleModels).State = EntityState.Modified;

            try
            {
                await ProbeProblemDatabase.Instance.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                // This is a specific problem, let's flag it
                if (!ProbeProblemDatabase.ArticleModelsExists(articleModels.Id))
                {
                    throw new IndexOutOfRangeException();
                }
                else
                {
                    throw;
                }
            }
        }
コード例 #27
0
        public ActionResult Detail(int id)
        {
            string       currentUser = HttpContext.User.Identity.Name;
            Notification notifi      = notiSrv.Getbykey(id);

            try
            {
                if (notifi != null)
                {
                    if (notifi.CreateBy.ToLower().Equals(currentUser.ToLower()))
                    {
                        int articleId               = notifi.ArticleId;
                        IArticlesService artSrv     = IoC.Resolve <IArticlesService>();
                        ICategoryService artCateSrv = IoC.Resolve <ICategoryService>();
                        ArticleModels    model      = new ArticleModels();
                        model.Article      = artSrv.Getbykey(id);
                        model.Categories   = artCateSrv.Query.OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList();
                        model.Notification = notifi;
                        return(View(model));
                    }
                    else
                    {
                        Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                        return(View("Index"));
                    }
                }
                else
                {
                    Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                    return(View("Index"));
                }
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Notification - Details : " + id, "Details Notification Error : " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                return(View("Index"));
            }
        }
コード例 #28
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        private IEnumerable <ArticlePosterModels> GetPoster(ArticleModels item, string posters)
        {
            if (posters == null || posters.Count() == 0)
            {
                return(new ArticlePosterModels[] { });
            }

            IEnumerable <ArticlePosterModels> articlePosters = ArticleDAO.GetItemPosters(item.ID);

            foreach (ArticlePosterModels p in articlePosters)
            {
                if (!string.IsNullOrWhiteSpace(p.Photo))
                {
                    ResourceImagesModels photo = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(p.Photo);
                    if (photo.Img != string.Empty)
                    {
                        p.Photo = photo.Img;
                    }
                }
            }
            return(articlePosters);
        }
コード例 #29
0
        /// <summary>
        /// Details view for a specific article
        /// </summary>
        /// <param name="_id"></param>
        /// <returns></returns>
        public ActionResult Details(int?_id)
        {
            if (_id == null)
            {
                return(RedirectToAction("Index", "Home"));          //To avoid accidental calls from Details view.
            }
            JsonArticle JsonArticle = new JsonArticle();

            using (var webClient = new System.Net.WebClient())
            {
                //Specified encoding to avoid issues related to German language characters
                webClient.Encoding = Encoding.UTF8;

                var json = webClient.DownloadString(ENDPOINT);

                //Deserializes to a List of Json Articles and queries an article with matching ID.
                JsonArticle = JsonConvert.DeserializeObject <List <JsonArticle> >(json).Where(x => x.id == _id).FirstOrDefault();
            }

            ArticleModels temp = Helpers.JsonToArticleModel(JsonArticle, true);

            return(View(temp));
        }
コード例 #30
0
ファイル: ArticleController.cs プロジェクト: jim-deng-git/Ask
        public void Move(long siteId, long menuId, long[] ArticleIds, long TargetMenuID)
        {
            ViewBag.SiteID     = siteId;
            ViewBag.MenuID     = menuId;
            ViewBag.ActionType = "move";
            if (ArticleIds.Length == 0)
            {
                return;
            }
            foreach (long ArticleId in ArticleIds)
            {
                ArticleModels articleItem = ArticleDAO.GetItem(ArticleId);
                CardsModels   cardItem    = CardsDAO.GetByNo(articleItem.CardNo);
                ZonesModels   zoneItem    = ZonesDAO.GetByNo(cardItem.ZoneNo.Value);
                PagesModels   pageItem    = PagesDAO.GetPageInfo(zoneItem.PageNo);

                var targetMenu = MenusDAO.GetInfo(TargetMenuID);
                WorkV3.Golbal.PubFunc.MovePage(pageItem, targetMenu.SiteID, targetMenu.ID);
                ArticleDAO.Move(ArticleId, targetMenu.ID, targetMenu.SiteID);
                WorkV3.Golbal.PubFunc.CopyIcon(articleItem.Icon, siteId, menuId, targetMenu.SiteID, targetMenu.ID);
                WorkV3.Golbal.PubFunc.CopyParagraphPhotos(articleItem.ID, siteId, menuId, targetMenu.SiteID, targetMenu.ID);
            }
        }