Example #1
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));
            }
        }
Example #2
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));
            }
        }
Example #3
0
        public ActionResult Approved(int id, bool error = false)
        {
            IArticlesService artSrv = IoC.Resolve <IArticlesService>();
            Articles         model  = artSrv.Getbykey(id);

            try
            {
                TryUpdateModel <Articles>(model);
                if (error)
                {
                    INotificationService notiSrv = IoC.Resolve <INotificationService>();
                    Notification         notifi  = new Notification();
                    notifi.ApproveBy   = HttpContext.User.Identity.Name;
                    notifi.CreateBy    = model.CreatedBy;
                    notifi.CreateDate  = DateTime.Now;
                    notifi.ArticleId   = id;
                    notifi.Description = model.Comment;
                    notiSrv.CreateNew(notifi);
                    notiSrv.CommitChanges();
                    Messages.AddErrorFlashMessage("Yêu cầu sửa lỗi đã được gửi.");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.Approved     = true;
                    model.ApproveBy    = HttpContext.User.Identity.Name;
                    model.ApproveDate  = DateTime.Now;
                    model.ModifiedDate = DateTime.Now;
                    model.URLName      = string.Format("{0}-{1}", model.URLName, model.Id);
                    artSrv.Save(model);
                    artSrv.CommitChanges();
                    Messages.AddFlashMessage("Tin đã được phê duyệt thành công.");
                    logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Tin tức - Duyệt :" + model.Id, "Approve Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Tin tức - Duyệt :" + model.Id, "Approve Error " + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorFlashMessage("Tin chưa được duyệt, vui lòng thực hiện lại.");
                return(View("Approve", model));
            }
        }
Example #4
0
        public ActionResult UpdateArt(int id)
        {
            IArticlesService artSrv = IoC.Resolve <IArticlesService>();
            Articles         model  = artSrv.Getbykey(id);

            try
            {
                TryUpdateModel <Articles>(model);
                model.ModifiedDate = DateTime.Now;
                model.ModifiedBy   = HttpContext.User.Identity.Name;
                artSrv.Save(model);
                artSrv.CommitChanges();
                Messages.AddFlashMessage("Tin đã được chỉnh sửa thành công.");
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - UpdateArt : " + model.Id, "Edit complete", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                return(RedirectToAction("ApproveIndex", new { CatID = model.CategoryID }));
            }
            catch (Exception ex)
            {
                logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Article - UpdateArt :" + model.Id, "Edit Error:" + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser);
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                return(View("EditArt", model));
            }
        }