public bool updateProducer(int id, Producer p, int adminid)
 {
     return _category.updateProducer(id,p,adminid );
 }
 public bool updateProducer(int id, Producer p, int adminid)
 {
     if (p != null && id != 0 && adminid != 0)
         return true;
     return false; 
 }
 public bool AddProducer(Producer prod, int id)
 {
     return _category.AddProducer(prod, id);
 }
 public bool AddProducer(Producer prod, int id)
 {
     if (prod != null && id != 0)
         return true;
     return false; 
 }
 public Producer producerDetails(int id)
 {
     Producer p = new Producer()
     {
         id = id,
         name = "En produsent"
     };
     return p; 
 }
 public List<Producer> getAllProducers(int? id)
 {
     var prod = new Producer()
     {
         id = 1,
         name = "Harry Potter"
     };
     var prod2 = new Producer()
     {
         id = 2,
         name = "Hermine Granger"
     };
     var prod3 = new Producer()
     {
         id = 3,
         name = "Ronald Weasley"
     };
     var prod4 = new Producer()
     {
         id = 4,
         name = "Albus Dumbledore"
     };
     var prod5 = new Producer()
     {
         id = 5,
         name = "Voldemort"
     };
     List<Producer> prodlist = new List<Producer>();
     prodlist.Add(prod);
     prodlist.Add(prod2);
     prodlist.Add(prod3);
     prodlist.Add(prod4);
     prodlist.Add(prod5);
     return prodlist;
 }
 public List<Producer> getResultProducer(int? id, string sc)
 {
     var cat = new Producer()
     {
         id = 1,
         name = "Rusbrus",
     };
     List<Producer> sublist = new List<Producer>();
     sublist.Add(cat);
     return sublist;
 }
        public ActionResult ProducerDetails(int id,ProducerInfo pi)
        {
            if (!isAdmin())
                return RedirectToAction("LogIn", "Main");

            if (ModelState.IsValid)
            {
                Customer c = (Customer)Session["loggedInUser"];
                Producer p = new Producer();
                p.name = pi.prodName;
                var result = _categoryBLL.updateProducer(id , p, c.id);
                if(result)
                    return Json(new { success = true, message = p.name + " ble endret.", redirect = "/Category/ListProducers/" });
                return Json(new { success = false, message = "noe gikk galt, prøv igjen senere." });
            }
            return Json(new { success = false, message = "Feil i validering" });
        }
        public ActionResult addProducer(ProducerInfo producerinfo)
        {
            if (!isAdmin())
                return RedirectToAction("LogIn", "Main");

            if (ModelState.IsValid)
            {
                Customer c = (Customer)Session["loggedInUser"];
                Producer prod = new Producer();
                prod.id = producerinfo.prodId;
                prod.name = producerinfo.prodName;
                bool OK = _categoryBLL.AddProducer(prod, c.id);
                if (OK)
                    return Json(new { success = true, message = prod.name + " ble lagt til.", redirect = "/Category/ListProducers?item_desc" });
                return Json(new { success = false, message = "noe gikk galt, prøv igjen senere." });
            }
            return Json(new { success = false, message = "Feil i validering" });
        }
        public bool updateProducer(int id, Producer p, int adminid)
        {
            var db = new DatabaseContext();

            try
            {
                Producers prod = db.Producers.FirstOrDefault(pr => pr.Id  == id);
                prod.Id = id;
                prod.Name = p.name;
                db.SaveChanges(adminid);
                return true;
            }
            catch (Exception e)
            {
                writeToFile(e);
                return false;
            }
        }
        public Producer producerDetails(int id)
        {
            try
            {
                var db = new DatabaseContext();
                Producers produser = (Producers)db.Producers.FirstOrDefault(c => c.Id == id);
                Producer prod = new Producer()
                {
                    id = produser.Id,
                    name = produser.Name
                };

                return prod;
            }
            catch (Exception e)
            {
                writeToFile(e);
                return null;
            }
        }
        public bool AddProducer(Producer producer, int id)
        {
            var newProducer = new Producers()
            {
                Name = producer.name
            };

            try
            {
                var db = new DatabaseContext();
                db.Producers.Add(newProducer);
                db.SaveChanges(id);
                return true;
            }
            catch (Exception fail)
            {
                writeToFile(fail);
                return false;
            }
        }