Exemplo n.º 1
0
        public ActionResult Create(Content collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // TODO: Add insert logic here

                    ContentDao bdDao  = new ContentDao();
                    string     detail = collection.Detail;
                    UserLogin  us     = (UserLogin)Session[CommonConstant.USER_SESSION];
                    collection.CreateDate   = Hepper.GetDateServer();
                    collection.ModifiedDate = Hepper.GetDateServer();
                    collection.CreateBy     = us.UserName;
                    collection.ModifiedBy   = us.UserName;
                    if (bdDao.Insert(collection) > 0)
                    {
                        SetAlert("Thêm thành công", "success");
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        SetAlert("Không thêm được", "danger");
                    }
                }
                return(View());
            }
            catch
            {
                SetAlert("Không thêm được", "danger");
                return(View());
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(ContentViewModel contentView)
        {
            if (ModelState.IsValid)
            {
                Content content = new Content();
                content.Name        = contentView.Name.Trim();
                content.MetaTitle   = contentView.MetaTitle;
                content.Image       = contentView.Image;
                content.Description = contentView.Description;
                content.Detail      = contentView.Detail;
                content.CategoryID  = contentView.CategoryID;
                content.Status      = contentView.Status;

                var contentDao  = new ContentDao();
                var categoryDao = new CategoryDao();

                long result = contentDao.Insert(content);
                if (result > 0)
                {
                    ShowNotify("Add successfully", "success");
                    return(RedirectToAction("Index", "Content"));
                }
                else if (result == -1)
                {
                    ShowNotify("This '" + categoryDao.GetByID(content.CategoryID).Name + "' category is locked", "error");
                }
                else
                {
                    ShowNotify("System error", "error");
                }
            }

            SetViewBagCategory(null, false);
            return(View("Create"));
        }
 public ActionResult Create(Content content)
 {
     if (ModelState.IsValid)
     {
         var _userLogin = new UserLogin();
         _userLogin = (UserLogin)HttpContext.Session["USER_SESSION"];
         var dao = new ContentDao();
         var res = dao.Insert(content, _userLogin.ID);
         if (res)
         {
             SetViewBag();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Them moi that bai");
         }
     }
     else
     {
         ModelState.AddModelError("", "Vui long kiem tra nhap lieu");
     }
     SetViewBag();
     return(View("Index"));
 }
Exemplo n.º 4
0
        public ActionResult Create(CONTENT ct)
        {
            var dao      = new ContentDao();
            int inserted = dao.Insert(ct);

            return(View());
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ID,Name,MetaTitle,Description,Detail,Image,CreateDate,CreateBy,ModifiedDate,ModifiedBy,MetaKeywords,MetaDescription,Content_Category_ID,Status")] Content content, HttpPostedFileBase image)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var dao      = new ContentDao();
                    var filename = "";
                    var path     = "";
                    if (image != null)
                    {
                        filename = DateTime.Now.ToString("dd-MM-yy-hh-mm-ss-") + image.FileName;
                        path     = Path.Combine(Server.MapPath("~/Image"), filename);
                        image.SaveAs(path);
                        content.Image = filename;
                    }
                    //else
                    //{

                    //    content.Image = "~/Image/logo.png";
                    //}
                    content.Name                = content.Name;
                    content.CreateDate          = Convert.ToDateTime(DateTime.UtcNow.ToLocalTime());
                    content.MetaTitle           = Functions.ConvertToUnSign(content.Name);
                    content.Description         = content.Description;
                    content.Detail              = content.Detail;
                    content.Content_Category_ID = content.Content_Category_ID;
                    content.Status              = Convert.ToBoolean(true);
                    var id = dao.Insert(content);
                    if (id > 0)
                    {
                        SetAlert("Thêm mới thành thành công", "success");
                        ViewBag.Success = "Thêm thành công";
                        content         = new Content();
                        return(RedirectToAction("Index", "Content"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Thêm mới ko thành công");
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                throw e;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            SetViewBag();
            return(View(content));
        }
        public ActionResult Create(Content content)
        {
            if (ModelState.IsValid)
            {
                //Xử lý MetaTitle, sau đó insert content đã được xử lý vào database
                if (!string.IsNullOrEmpty(content.Name))
                {
                    content.MetaTitle = StringHelper.ToUnsignString(content.Name);
                }

                var  dao = new ContentDao();
                long id  = dao.Insert(content);

                //Xử lý bảng Tag, ContentTag
                if (!string.IsNullOrEmpty(content.Tags))
                {
                    string[] tags = content.Tags.Split(',');
                    foreach (var tag in tags)
                    {
                        var tagId         = StringHelper.ToUnsignString(tag);
                        var tagDao        = new TagDao();
                        var contentTagDao = new ContentTagDao();
                        var existedTag    = tagDao.CheckTag(tagId);

                        //insert vào bảng Tag trong database
                        if (!existedTag)
                        {
                            tagDao.Insert(tagId, tag);
                        }

                        //insert vào bảng ContentTag
                        contentTagDao.Insert(content.ID, tagId);
                    }
                }

                if (id > 0)
                {
                    SetAlert("Create a new content successfully.", "success");
                    return(RedirectToAction("Index", "Content"));
                }
                else
                {
                    ModelState.AddModelError("", "Create a new content failed.");
                    return(RedirectToAction("Create", "Content"));
                }
            }
            SetContentCategoryIDViewBag();
            return(View(content));
        }
 public ActionResult Insert(Content model)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ContentDao();
         long id  = dao.Insert(model);
         if (id > 0)
         {
             return(RedirectToAction("Create", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm tin tức không thành công");
             return(View(model));
         }
     }
     return(View("Create"));
 }
Exemplo n.º 8
0
        public ActionResult Create(Content model)
        {
            if (ModelState.IsValid)
            {
                var dao = new ContentDao();

                long id = dao.Insert(model);
                if (id > 0)
                {
                    return(RedirectToAction("Index", "Content"));
                }
                else
                {
                    ModelState.AddModelError("", "Them content thanh cong");
                }
            }
            return(View("Index"));
        }
 public ActionResult Create(Content model)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ContentDao();
         long id  = dao.Insert(model);
         if (id > 0)
         {
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm user không thành công");
         }
     }
     SetViewBag();
     return(View());
 }
Exemplo n.º 10
0
 public ActionResult Create(Content content)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ContentDao();
         long id  = dao.Insert(content);
         if (id > 0)
         {
             setAlert("Thêm mới thành công", "success");
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Không thêm được");
         }
     }
     return(View("Index"));
 }
Exemplo n.º 11
0
 public ActionResult Create(Content content)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ContentDao();
         long id  = dao.Insert(content);
         if (id > 0)
         {
             SetAlert("Thêm mới tin tức THÀNH CÔNG", "success");
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm mới tin tức KHÔNG thành công");
         }
     }
     SetViewBag();
     return(View("Index"));
 }
Exemplo n.º 12
0
 public ActionResult Create(CONTENT model)
 {
     if (ModelState.IsValid)
     {
         var  dao = new ContentDao();
         long id  = dao.Insert(model);
         if (id > 0)
         {
             SetAlert("Thêm tin tức thành công", "success");
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm tin tức không thành công");
         }
     }
     SetViewBag(model.ID);
     return(View("Index"));
 }
Exemplo n.º 13
0
 public ActionResult Create(Content model)
 {
     if (ModelState.IsValid)
     {
         var  dao     = new ContentDao();
         bool created = dao.Insert(model);
         if (created)
         {
             SetAlert("Thêm bài viết thành công ", "success");
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm thất bại !!!");
         }
     }
     SetViewBag();
     return(View());
 }
Exemplo n.º 14
0
 public ActionResult Create(Content model)
 {
     if (ModelState.IsValid)
     {
         var contentDao = new ContentDao();
         model.MetaTitle = Converter.ConvertToUnSign(model.Name);
         var session = (UserLogin)Session[CommonConstants.USER_SESSION];
         model.CreatedBy = session.UserName;
         var rs = contentDao.Insert(model);
         if (rs > 0)
         {
             SetAlert("Insert success!", "success");
             return(RedirectToAction("Index", "Content"));
         }
         else
         {
             ModelState.AddModelError("", "Insert failed, check the contents again");
         }
     }
     SetViewBag();
     return(View("Create"));
 }
Exemplo n.º 15
0
 public ActionResult Create(Content content)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dao    = new ContentDao();
             var result = dao.Insert(content);
             if (result > 0)
             {
                 return(RedirectToAction("Index", "Content"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm mới không thành công");
             }
         }
     }
     catch (Exception ex)
     {
     }
     return(RedirectToAction("Index", "Create"));
 }
Exemplo n.º 16
0
 public ActionResult Add(ContentsModel input)
 {
     if (ModelState.IsValid)
     {
         input.UserId   = SessionHelper.GetSessionUser().UserId;
         input.Taxonomy = input.Taxonomy ?? "Content";
         input.Status   = input.Status ?? true;
         input.View     = input.View ?? 0;
         input.Order    = input.Order ?? 0;
         input.Date     = input.Date ?? DateTime.Now;
         input.Modified = input.Modified ?? DateTime.Now;
         var entity = new tb_Contents();
         entity.CategoryId       = input.CategoryId;
         entity.Content          = input.Content;
         entity.Date             = input.Date;
         entity.Description      = input.Description;
         entity.Id               = input.Id;
         entity.Meta_Description = input.Meta_Description;
         entity.Meta_Keyword     = input.Meta_Keyword;
         entity.Meta_Title       = input.Meta_Title;
         entity.Modified         = input.Modified;
         entity.Name             = input.Name;
         entity.Order            = input.Order;
         entity.ParentId         = input.ParentId;
         entity.Slug             = input.Slug;
         entity.Status           = input.Status;
         entity.Taxonomy         = input.Taxonomy;
         entity.Thumbnail        = input.Thumbnail;
         entity.Title            = input.Title;
         entity.UserId           = input.UserId;
         entity.View             = input.View;
         long Id = Dao.Insert(entity);
         return(RedirectToAction("Edit", "Contents", new { Id = Id }));
     }
     ViewBag.CategoryId = new SelectList(DaoCategories.ListAllByTaxonomy("Content"), "Id", "Title", input.CategoryId);
     return(View(input));
 }