예제 #1
0
        public ActionResult  DeleteCategory(int id)
        {
            CategoryMast category = db.CategoryMasts.Find(id);

            db.CategoryMasts.Remove(category);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Add([Bind(Include = "CategoryName")] CategoryMast category)
        {
            if (ModelState.IsValid)
            {
                db.CategoryMasts.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
예제 #3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                //return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
                return(RedirectToAction("Index"));
            }

            CategoryMast category = db.CategoryMasts.Find(id);

            return(View(category));
        }
예제 #4
0
        public ActionResult Edit([Bind(Include = "CategoryId,CategoryName")] CategoryMast category)
        {
            if (ModelState.IsValid)
            {
                //db.Entry(category).State = EntityState.Modified;

                CategoryMast categoryEntity = db.CategoryMasts.Find(category.CategoryID);
                categoryEntity.CategoryName = category.CategoryName;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
예제 #5
0
        public IActionResult Index(CategoryMast objCategoryMast)
        {
            if (isAdmin)
            {
                try
                {
                    var draw = HttpContext.Request.Form["draw"].FirstOrDefault();

                    // Skip number of Rows count
                    var start = Request.Form["start"].FirstOrDefault();

                    // Paging Length 10,20
                    var length = Request.Form["length"].FirstOrDefault();

                    // Sort Column Name
                    var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();

                    // Sort Column Direction (asc, desc)
                    var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();

                    // Search Value from (Search box)
                    var searchValue = Request.Form["search[value]"].FirstOrDefault();

                    //Paging Size (10, 20, 50,100)
                    int pageSize = length != null?Convert.ToInt32(length) : 0;

                    int skip = start != null?Convert.ToInt32(start) : 0;

                    int recordsTotal = 0;

                    var data = _auditToolContext.Category.Where(x => x.IsActive == true).ToList();
                    objCategoryMast = new CategoryMast
                    {
                        CategoryList = new List <Category>()
                    };
                    foreach (var item in data)
                    {
                        Category objCategory = new Category
                        {
                            CatgId          = item.CatgId,
                            CatgDescription = item.CatgDescription
                        };
                        objCategoryMast.CategoryList.Add(objCategory);
                    }

                    // getting all Customer data
                    var customerData = (from tempcustomer in objCategoryMast.CategoryList
                                        select tempcustomer);

                    //Sorting
                    if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
                    {
                        switch (sortColumn)
                        {
                        case "CatgDescription":
                            if (sortColumnDirection == "desc")
                            {
                                customerData = customerData.OrderByDescending(s => s.CatgDescription);
                            }
                            else
                            {
                                customerData = customerData.OrderBy(s => s.CatgDescription);
                            }
                            break;
                        }
                    }
                    //Search
                    if (!string.IsNullOrEmpty(searchValue))
                    {
                        customerData = customerData.Where(m => m.CatgDescription.ToLower().StartsWith(searchValue.ToLower()));
                    }

                    //total number of rows counts
                    recordsTotal = customerData.Count();
                    //Paging
                    var jsonData = customerData.Skip(skip).Take(pageSize).ToList();
                    //Returning Json Data
                    return(Json(new { draw, recordsFiltered = recordsTotal, recordsTotal, data = jsonData }));
                }
                catch (Exception ex)
                {
                    _log.WriteErrorLog(new LogItem {
                        ErrorType = "Error", ErrorSource = "CategoryController_Index_objCategoryMast", ErrorDiscription = ex.InnerException != null ? ex.InnerException.ToString() : ex.Message
                    });
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
예제 #6
0
        public ActionResult Edit(int id)
        {
            CategoryMast category = db.CategoryMasts.Find(id);

            return(View(category));
        }