Beispiel #1
0
 public bool UpdateVaDuyet(CMS_News entity)
 {
     try
     {
         CMS_News obj = MyContext.CMS_News.Find(entity.ID);
         obj.TITLE         = entity.TITLE;
         obj.CONTENTS      = entity.CONTENTS;
         obj.EXCERPT       = entity.EXCERPT;
         obj.ID_CATEGORIES = entity.ID_CATEGORIES;
         obj.PICTURE       = entity.PICTURE;
         obj.EDITDATE      = System.DateTime.Now;
         obj.ID_USERMODIFY = entity.ID_USERMODIFY;
         if (obj.ID_NEWS_STATUS == 1 || obj.ID_NEWS_STATUS == 3 || obj.ID_NEWS_STATUS == 6)
         {
             obj.ID_NEWS_STATUS = 2;
         }
         MyContext.Entry(obj).State = EntityState.Modified;
         MyContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(false);
     }
 }
Beispiel #2
0
        public ActionResult Create(FormCollection fc, CMS_News obj)
        {
            try
            {
                TempData.Keep("categories");
                if (ModelState.IsValid)
                {
                    CMS_News_DAO  objDAO     = new CMS_News_DAO();
                    CSF_Users_DAO objUserDao = new CSF_Users_DAO();
                    int           userID     = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name);
                    obj.ID_USERCREATE = userID;

                    int ReturnID = objDAO.Insert(obj);
                    if (ReturnID > 0)
                    {
                        SetAlert("Thêm tin tức thành công", AlertType.Success);
                        return(RedirectToAction("Index", "CMS_News"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm tin tức không thành công");
                    }
                    return(View("Index"));
                }
                return(View());
            }
            catch (Exception ex)
            {
                SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
                Logs.WriteLog(ex);
                return(View());
            }
        }
Beispiel #3
0
 public ActionResult Edit(FormCollection fc, CMS_News obj)
 {
     try
     {
         if (ModelState.IsValid)
         {
             CMS_News_DAO  objDAO     = new CMS_News_DAO();
             CSF_Users_DAO objUserDao = new CSF_Users_DAO();
             int           userID     = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name);
             obj.ID_USERMODIFY = userID;
             bool update = false;
             update = objDAO.Update(obj);
             if (update)
             {
                 SetAlert("Cập nhật tin tức thành công", AlertType.Success);
                 return(RedirectToAction("Index", "CMS_News"));
             }
             else
             {
                 SetAlert("Cập nhật không thành công", AlertType.Error);
             }
         }
         return(View(obj));
     }
     catch (Exception ex)
     {
         SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error);
         Logs.WriteLog(ex);
         return(View());
     }
 }
Beispiel #4
0
        public bool CreateOrUpdate(CMS_NewsModels model, ref string msg)
        {
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                using (var trans = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        if (string.IsNullOrEmpty(model.Id))
                        {
                            var _Id = Guid.NewGuid().ToString();
                            var e   = new CMS_News
                            {
                                Id                = _Id,
                                Title             = model.Title,
                                Short_Description = model.Short_Description,
                                ImageURL          = model.ImageURL,
                                CreatedBy         = model.CreatedBy,
                                CreatedDate       = DateTime.Now,
                                Description       = model.Description,
                                UpdatedBy         = model.UpdatedBy,
                                UpdatedDate       = DateTime.Now,
                                IsActive          = model.IsActive
                            };
                            cxt.CMS_News.Add(e);
                        }
                        else
                        {
                            var e = cxt.CMS_News.Find(model.Id);
                            if (e != null)
                            {
                                e.Title             = model.Title;
                                e.Short_Description = model.Short_Description;
                                e.ImageURL          = model.ImageURL;
                                e.Description       = model.Description;
                                e.UpdatedBy         = model.UpdatedBy;
                                e.UpdatedDate       = DateTime.Now;
                                e.IsActive          = model.IsActive;
                            }
                        }
                        cxt.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        Result = false;
                        msg    = "Vui lòng kiểm tra đường truyền";
                        trans.Rollback();
                    }
                    finally
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(Result);
        }
Beispiel #5
0
 public bool UpdateTrangThai(int iIDNews, Int16 iTrangThai, Int16 iTieuDiem)
 {
     try
     {
         CMS_News obj = MyContext.CMS_News.Find(iIDNews);
         obj.ID_NEWS_STATUS = iTrangThai;
         obj.ISFOCUS        = iTieuDiem;
         MyContext.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         return(false);
     }
 }
Beispiel #6
0
 public int Insert(CMS_News entity)
 {
     try
     {
         entity.CREATEDATE   = System.DateTime.Now;
         entity.NUMBEROFVIEW = 0;
         entity.ISFOCUS      = 0;
         MyContext.CMS_News.Add(entity);
         MyContext.SaveChanges();
         return(entity.ID);
     }
     catch (Exception ex)
     {
         Logs.WriteLog(ex);
         throw;
     }
 }
Beispiel #7
0
        public bool CreateOrUpdate(CMS_NewsModels model, ref string msg)
        {
            NSLog.Logger.Info("NewsCreateOrUpdate", model);
            var Result = true;

            using (var cxt = new CMS_Context())
            {
                try
                {
                    if (string.IsNullOrEmpty(model.Id)) /* insert */
                    {
                        var _Id = Guid.NewGuid().ToString();
                        var e   = new CMS_News
                        {
                            Id                = _Id,
                            Title             = model.Title,
                            Link              = model.Link,
                            Short_Description = model.Short_Description,
                            Type              = model.Type,
                            ImageURL          = model.ImageURL,
                            Description       = model.Description,
                            IsActive          = model.IsActive,
                            Author            = model.Author,
                            Category          = model.Category,
                            Source            = model.Source,
                            CreatedUser       = model.CreatedBy,
                            CreatedDate       = DateTime.Now,
                            ModifiedUser      = model.UpdatedBy,
                            LastModified      = DateTime.Now,
                            Status            = (byte)Commons.EStatus.Actived,
                        };
                        cxt.CMS_News.Add(e);
                    }
                    else /* updated */
                    {
                        var e = cxt.CMS_News.Find(model.Id);
                        if (e != null)
                        {
                            e.Title             = model.Title;
                            e.Short_Description = model.Short_Description;
                            e.Type         = model.Type;
                            e.Link         = model.Link;
                            e.ImageURL     = model.ImageURL;
                            e.Description  = model.Description;
                            e.Author       = model.Author;
                            e.Source       = model.Source;
                            e.Category     = model.Category;
                            e.ModifiedUser = model.UpdatedBy;
                            e.LastModified = DateTime.Now;
                            e.IsActive     = model.IsActive;
                        }
                    }

                    cxt.SaveChanges();
                    NSLog.Logger.Info("ResponseNewsCreateOrUpdate", new { Result, msg });
                }
                catch (Exception ex)
                {
                    Result = false;
                    msg    = "Vui lòng kiểm tra đường truyền";
                    NSLog.Logger.Error("ErrorNewsCreateOrUpdate", ex);
                }
            }
            return(Result);
        }