public List<SubCategory> getAllSub(int? id)
        {
            var cat = new SubCategory()
            {
                ID = 1,
                name = "Rusbrus",
                catName = "ØL"
            };
            var cat1 = new SubCategory()
            {
                ID = 2,
                name = "Preskanne",
                catName = "Kaffe"
            };
            var cat2 = new SubCategory()
            {
                ID = 3,
                name = "Pulver",
                catName = "Kaffe"
            };
            var cat3 = new SubCategory()
            {
                ID = 4,
                name = "Mokka",
                catName = "Kaffe"
            };
            var cat4 = new SubCategory()
            {
                ID = 5,
                name = "Latte",
                catName = "Kaffe"
            };

            List<SubCategory> sublist = new List<SubCategory>();
            sublist.Add(cat);
            sublist.Add(cat1);
            sublist.Add(cat2);
            sublist.Add(cat3);
            sublist.Add(cat4);

            return sublist;
        }
Ejemplo n.º 2
0
 public bool update(int id, SubCategory sc)
 {
     return _category.update(id, sc);
 }
Ejemplo n.º 3
0
 public bool AddSub(int adminId, SubCategory sc)
 {
     return _category.AddSub(adminId,sc);
 }
        public void category_subcategories_details_view()
        {
            //Arrange
            TestControllerBuilder builder = new TestControllerBuilder();
            var controller = new CategoryController(new CategoryBLL(new CategoryDALStub()));
            builder.InitializeController(controller);
            builder.HttpContext.Session["loggedInUser"] = new Customer() { id = 1, admin = true };

            SubCategory expected = new SubCategory()
            {
                ID = 4,
                name = "Mokka",
                catName = "Kaffe"
            }; 

            //Act
            var action = (ViewResult)controller.SubCatDetails(expected.ID);
            var result = (SubCategoryDetail)action.Model;

            //Assert
            Assert.AreEqual("", action.ViewName);
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.categoryList);  
        }
 public bool update(int id, SubCategory sc)
 {
     if (id == 0)
     {
         return false;
     }
     return true;
 }
 public bool AddSub(int id, SubCategory category)
 {
     if (id == 0)
         return false;
     return true;
 }
 public bool update(int id, SubCategory sc, int adminid)
 {
     if (id == 0)
         return false;
     return true;
 }
 public List<SubCategory> getResultSub(int? id, string sc)
 {
     var cat = new SubCategory()
     {
         ID = 1,
         name = "Rusbrus",
         catName = "ØL"
     };
     List<SubCategory> sublist = new List<SubCategory>();
     sublist.Add(cat);
     return sublist;
 }
        public ActionResult SubCatDetails(SubCategoryDetail sc)
        {
            if (!isAdmin())
            {
                return RedirectToAction("LogIn", "Main");
            }
            if (ModelState.IsValid)
            {
                SubCategory updated = new SubCategory()
                {
                    ID = sc.ID,
                    name = sc.name,
                    catId = sc.categoryId,
                };
                Customer admin = (Customer)Session["loggedInUser"];
                var adminid = admin.id;
                bool result = _categoryBLL.update(adminid, updated);
    
                sc.categoryList = _categoryBLL.getAll(null).Select(c => new SelectListItem { Value = c.ID.ToString(), Text = c.name }).ToList();

                if (result)
                    return Json(new { success = true, message = "Subkategorien ble endret", redirect = "/Category/ListSubCategories" });
                return Json(new { success = false, message = "Noe gikk galt, prøv igjen senenere" });
            }
            return Json(new { success = false, message = "feil i validering" });
        }
Ejemplo n.º 10
0
        public bool update(int id, SubCategory sc)
        {
            var db = new DatabaseContext();
            SubCategories existing = db.SubCategories.FirstOrDefault(u => u.Id == sc.ID);
            try
            {
                existing.Name = sc.name;
                existing.CategoriesId = sc.catId;

                db.SaveChanges(id);
            }
            catch (Exception e)
            {
                writeToFile(e);
                return false;
            }
            return true;
        }
Ejemplo n.º 11
0
        public SubCategory SubCatDetails(int id)
        {
            try
            {
                var db = new DatabaseContext();
                SubCategories subcat = (SubCategories)db.SubCategories.FirstOrDefault(c => c.Id == id);
                SubCategory subcategory = new SubCategory()
                {
                    ID = subcat.Id,
                    name = subcat.Name,
                    catId = subcat.CategoriesId
                };

                return subcategory;
            }
            catch(Exception e)
            {
                writeToFile(e);
                return null; 
            }
        }
Ejemplo n.º 12
0
 public bool AddSub(int adminId, SubCategory sc)
 {
     var db = new DatabaseContext();
     db.SubCategories.Add(new SubCategories()
     {
         Name = sc.name,
         CategoriesId = sc.catId
     });
     try
     {
         db.SaveChanges(adminId);
     }
     catch(Exception e)
     {
         writeToFile(e);
         return false; 
     }
     return true;
 }