Example #1
0
        public void TestGetCategory()
        {
            CategoryModel categoryModel = new CategoryModel();
            Category      categoryMovie = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork  = new Category(CATEGORY_NAME_WORK);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            Assert.AreEqual(categoryMovie, categoryModel.GetCategory(0));
            Assert.AreEqual(categoryWork, categoryModel.GetCategory(1));
            Assert.AreEqual(new Category(string.Empty), categoryModel.GetCategory(2));
        }
        public ActionResult FixValueProviderPost()
        {
            //Value provider csak az URL paraméterrel dolgozik
            var querystringValues = new QueryStringValueProvider(this.ControllerContext);
            var routeValues       = new RouteDataValueProvider(this.ControllerContext);

            ValueProviderResult action     = querystringValues.GetValue("action");      //action=null
            ValueProviderResult controller = querystringValues.GetValue("controller");  //controller=null

            ValueProviderResult idResult = querystringValues.GetValue("Id");            //idResult=null

            int    id         = (int)routeValues.GetValue("Id").ConvertTo(typeof(int)); //idResult=99999
            string EzNemValid = querystringValues.GetValue(key: "WillNeverValid").AttemptedValue;

            var model = CategoryModel.GetCategory(1);

            //A model.WillNeverValid értéke "Hát ez honnan jött?" lesz:
            this.TryUpdateModel <CategoryModel>(model, string.Empty, querystringValues);

            //Input mezők
            var  formValues = new FormValueProvider(this.ControllerContext);
            bool szerepel   = formValues.ContainsPrefix("prefix.WillNeverValid");

            this.TryUpdateModel <CategoryModel>(model, "prefix", formValues);

            return(RedirectToAction("FixValueProvider"));
        }
Example #3
0
        public ActionResult CategoryList()
        {
            var cat = new CategoryModel();
            var lst = cat.GetCategory().ToList();

            return(PartialView("_CategoryListPartial", lst));
        }
        public ActionResult EditTreePost(int id)
        {
            var model = CategoryModel.GetCategory(id);

            this.TryUpdateModel(model);
            return(RedirectToAction("ListTree"));
        }
        public ActionResult Edit6(int id)
        {
            var model = CategoryModel.GetCategory(id);

            //model.WillNeverValid = "Csak legyen valami";
            //1. Interface
            if (this.TryUpdateModel <ICategoryFullNameUpdateModel>(model))
            {
                //MindenOk.
                bool isValid = this.ModelState.IsValid;
            }

            //2. white list
            if (this.TryUpdateModel(model, string.Empty, new[] { "FullName" }))
            {
                //MindenOk.
                bool isValid = this.ModelState.IsValid;
            }

            //3. black list
            if (this.TryUpdateModel(model, string.Empty, null, new[] { "CreatedDate", "WillNeverValid" }))
            {
                //MindenOk.
                bool isValid = this.ModelState.IsValid;
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit()
        {
            int      id;
            DateTime createdDate;

            if (!Int32.TryParse(Request["Id"], out id))
            {
                return(Content("Id nem áll rendelkezésre"));
            }
            var model = CategoryModel.GetCategory(id);

            string nev = Request["FullName"];

            if (string.IsNullOrEmpty(nev))
            {
                return(Content("A nevet meg kell adni!"));
            }
            model.FullName = nev;

            if (DateTime.TryParse(Request.Form["CreatedDate"], out createdDate))
            {
                model.CreatedDate = createdDate;
            }
            else
            {
                return(Content("'Létrehozva' nem dátum"));
            }

            return(RedirectToAction("Index"));
        }
Example #7
0
        public ActionResult ShowBlog(int id)
        {
            var           result = objblog.getBlogbyids(id);
            CategoryModel model  = new CategoryModel();

            ViewBag.Categories = model.GetCategory();
            return(View(result));
        }
Example #8
0
        public JsonResult getProductCategories()
        {
            var categories = CategoryModel.GetCategory();

            return(new JsonResult {
                Data = categories, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public ActionResult Edit3(CategoryModel inputmodel, string fullname, string createdDate)
        {
            var model = CategoryModel.GetCategory(inputmodel.Id);

            model.FullName      = inputmodel.FullName;
            model.CreatedDate   = inputmodel.CreatedDate;
            model.SubCategories = inputmodel.SubCategories;
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit2(int id, string FuLNAme, string Fullname, string fullname, DateTime createdDate, List <CategoryModel> subCategories)
        {
            var model = CategoryModel.GetCategory(id);

            model.FullName      = FuLNAme;
            model.CreatedDate   = createdDate;
            model.SubCategories = subCategories;
            return(RedirectToAction("Index"));
        }
Example #11
0
        public void TestWriteCategoryToFile()
        {
            CategoryModel categoryModel         = new CategoryModel(); // TODO: 初始化為適當值
            Category      categoryMovie         = new Category(CATEGORY_NAME_MOVIE);
            Category      categoryWork          = new Category(CATEGORY_NAME_WORK);
            Category      categoryEntertainment = new Category(CATEGORY_NAME_ENTERTAINMENT);

            categoryModel.AddCategory(categoryMovie);
            categoryModel.AddCategory(categoryWork);
            categoryModel.AddCategory(categoryEntertainment);
            Assert.AreEqual(3, categoryModel.Categories.Count);
            categoryModel.WriteCategoryToFile();
            categoryModel = new CategoryModel();
            categoryModel.ReadCategoryFromFile();
            Assert.AreEqual(3, categoryModel.Categories.Count);
            Assert.AreEqual(categoryMovie, categoryModel.GetCategory(0));
            Assert.AreEqual(categoryWork, categoryModel.GetCategory(1));
            Assert.AreEqual(categoryEntertainment, categoryModel.GetCategory(2));
        }
        public ActionResult Edit7([Bind(Include = "FullName", Exclude = "CreatedDate,WillNeverValid")] CategoryModel inputmodel)
        {
            var model = CategoryModel.GetCategory(inputmodel.Id);

            model.FullName = inputmodel.FullName;

            //this.ModelState["WillNeverValid"].Errors.Clear();
            bool isValid = this.ModelState.IsValid;

            return(RedirectToAction("Index"));
        }
 public ActionResult CategoryList()
 {
     if (Convert.ToInt32(Session["UserRollId"]) == 1)
     {
         CategoryModel model      = new CategoryModel();
         var           Categories = model.GetCategory();
         return(View(Categories));
     }
     else
     {
         return(Redirect("/Admin/index"));
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         CategoryModel objCategorymodel = new CategoryModel();
         var           result           = objCategorymodel.GetCategory();
         repeater2.DataSource = result;
         repeater2.DataBind();
     }
     catch (Exception ex)
     {
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
     }
 }
        public ActionResult Edit4(int id)
        {
            try
            {
                var model = CategoryModel.GetCategory(id);
                this.UpdateModel(model);
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }

            return(RedirectToAction("Index"));
        }
Example #16
0
 public ActionResult Add_New()
 {
     if (Convert.ToInt32(Session["UserRollId"]) == 1)
     {
         CategoryModel model = new CategoryModel();
         ViewBag.Categories = model.GetCategory();
         Blog objtblResult = new Blog();
         return(View(objtblResult));
     }
     else
     {
         return(Redirect("/Admin/index"));
     }
 }
        public ActionResult Edit5(int id)
        {
            var model = CategoryModel.GetCategory(id);

            if (this.TryUpdateModel(model))
            {
                //Minden Ok, mehet a mentés
            }
            else
            {
                //Minden Ok, mehet a mentés
            }
            return(RedirectToAction("Index"));
        }
Example #18
0
 public ActionResult EditBlog(int id)
 {
     if (Convert.ToInt32(Session["UserRollId"]) == 1)
     {
         var           Blog  = objblog.getBlogbyid(id);
         CategoryModel model = new CategoryModel();
         ViewBag.Categories = model.GetCategory();
         return(View("Add_New", Blog));
     }
     else
     {
         return(Redirect("/Admin/index"));
     }
 }
        public async Task <IActionResult> Details(int id)
        {
            if (!HttpContext.Session.GetInt32("authenticated").HasValue)
            {
                return(new RedirectToActionResult("index", "login", null));
            }

            var category = await categoryModel.GetCategory(id);

            if (category == null)
            {
                return(NotFound());
            }

            return(View(category));
        }
        public ActionResult Edit1(int id, FormCollection coll)
        {
            try
            {
                var model = CategoryModel.GetCategory(id);
                ValueProviderResult fullname    = coll.GetValue("FullName");
                ValueProviderResult createdDate = coll.GetValue("CreatedDate");
                model.FullName    = (string)fullname.ConvertTo(typeof(string));
                model.CreatedDate = (DateTime)createdDate.ConvertTo(typeof(DateTime));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Details(int?id)
        {
            ViewBag.Loggedin = HttpContext.Session.GetInt32("authenticated").HasValue;
            if (id == null && !id.HasValue)
            {
                return(NotFound());
            }

            var category = await categoryModel.GetCategory(id.Value);

            if (category == null)
            {
                return(NotFound());
            }

            ViewBag.Categories = await categoryModel.GetAll();

            return(View(category));
        }
 public ActionResult DeleteCategory(int id, string sort = "", int page = 0)
 {
     if (Convert.ToInt32(Session["UserRollId"]) == 1)
     {
         CategoryModel categories = new CategoryModel();
         if (sort != "" && page != 0)
         {
             var Categories = categories.GetCategory();
             return(View("CategoryList", Categories));
         }
         else
         {
             categories.DeleteCategory(id);
             return(Redirect("/Admin/CategoryList"));
         }
     }
     else
     {
         return(Redirect("/Admin/index"));
     }
 }
Example #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    CategoryModel objCategoryModel = new CategoryModel();
                    BlogModel     objblog          = new BlogModel();
                    var           result           = objCategoryModel.GetCategory();
                    ddlCategory.DataSource     = result;
                    ddlCategory.DataValueField = "categoryId";
                    ddlCategory.DataTextField  = "CategoryName";
                    ddlCategory.DataBind();
                    int id = Convert.ToInt32(Request.QueryString["id"]);
                    if (id != 0)
                    {
                        lblHeadText.Text = "Update Blog";
                        btnSaveblog.Text = "Update";
                        var results = objblog.getBlogbyid(id);
                        ddlCategory.SelectedValue = Convert.ToString(results.CategoryId);
                        txtText.Text        = results.Text;
                        txtTitle.Text       = results.Title;
                        txtPublishDate.Text = Convert.ToString(results.published_Date_st);
                        img.ImageUrl        = results.Image;
                        Updateid.Value      = Convert.ToString(results.tblBlog_Id);
                    }

                    else
                    {
                        lblHeadText.Text = "Save Blog";
                        btnSaveblog.Text = "Save";
                    }
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
            }
        }
Example #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //----- for Result -------------------
                ResultModel model  = new ResultModel();
                var         result = model.GetResult();
                Repeater2.DataSource = result;
                Repeater2.DataBind();

                //-----------    for Blog------------------
                BlogModel obj     = new BlogModel();
                int       id      = Convert.ToInt32(Request.QueryString["id"]);
                var       results = obj.getCommentForApprove(id);
                hdnBlogId.Value      = Convert.ToString(id);
                ShowBlogs.DataSource = results;
                ShowBlogs.DataBind();

                //---------------------for Categories --------------------
                CategoryModel objcategoryModel = new CategoryModel();
                var           data             = objcategoryModel.GetCategory();
                Repeater1.DataSource = data;
                Repeater1.DataBind();

                //----------------------- for comments ----------------------

                //CommentModel objcommentmodel = new CommentModel();
                //var items = objcommentmodel.getCommentForApprove(id);
                //int totalcomment = items.Count();
                //TotalComment.Text = Convert.ToString(totalcomment);
                comments.DataSource = results;
                comments.DataBind();
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
            }
        }
 protected void repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Delete")
         {
             CategoryModel objresult = new CategoryModel();
             int           id        = Convert.ToInt32(e.CommandArgument);
             objresult.DeleteCategory(id);
             var result = objresult.GetCategory();
             repeater2.DataSource = result;
             repeater2.DataBind();
         }
         if (e.CommandName == "Edit")
         {
             int id = Convert.ToInt32(e.CommandArgument);
             Response.Redirect("AddCategory.aspx?id=" + id);
         }
     }
     catch (Exception ex)
     {
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
     }
 }
 public ActionResult Edit(int id)
 {
     return(View(categoryModel.GetCategory(id)));
 }
 public ActionResult EditTree(int id)
 {
     ViewData["depth"] = 1;
     return(View(CategoryModel.GetCategory(id)));
 }
 public ActionResult EditCategModelBinder(int id)
 {
     return(View(CategoryModel.GetCategory(id)));
 }
Example #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    //for results
                    ResultModel model  = new ResultModel();
                    var         result = model.GetResult();
                    Repeater2.DataSource = result;
                    Repeater2.DataBind();

                    //for blogs
                    string Text       = Convert.ToString(Request.QueryString["SearchText"]);
                    int    categoryId = Convert.ToInt32(Request.QueryString["CategoryId"]);
                    SearchPaging.Value = Convert.ToString(categoryId);

                    BlogModel objblogModel = new BlogModel();
                    var       results      = objblogModel.getBlog(categoryId);
                    if (results.Count() == 0)
                    {
                        lblMessage.Visible = true;
                        lblMessage.Text    = "No Item to Dispaly";
                    }

                    int PageIndex          = 0;
                    int PageSize           = 3;
                    int skip               = PageIndex * PageSize;
                    int PageCount          = Convert.ToInt32(Convert.ToDouble(Math.Ceiling((double)((double)results.Count() / (double)PageSize))));
                    List <BlogModel> query = results.Skip(skip).Take(PageSize).ToList();
                    BlogRepeater.DataSource = query;
                    BlogRepeater.DataBind();
                    List <PageModel> paging = new List <PageModel>();
                    Boolean          active = false;
                    for (int i = 0; i < PageCount; i++)
                    {
                        if (i == 0)
                        {
                            active = true;
                        }
                        else
                        {
                            active = false;
                        }
                        paging.Add(new PageModel
                        {
                            pageindex  = i,
                            pagename   = i + 1,
                            pageactive = active,
                        });
                    }
                    Repeater1.DataSource = paging;
                    Repeater1.DataBind();

                    //for categories
                    CategoryModel objcategory = new CategoryModel();
                    var           categories  = objcategory.GetCategory();
                    RepeaterCategories.DataSource = categories;
                    RepeaterCategories.DataBind();
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
            }
        }
Example #30
0
        public ActionResult ProductFilterB2B()
        {
            var cat = new CategoryModel();

            return(View(cat.GetCategory()));
        }