public JsonResult DeleteBerry(Prices prices)
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();

            string berry = prices.Berry;

            bool success = false;

            var delete = (from p in entity.Prices
                          where p.Berry == berry
                          select p).FirstOrDefault();

            if (delete != null)
            {
                ObjectContext oc = ((IObjectContextAdapter)entity).ObjectContext;
                oc.DeleteObject(delete);
                oc.SaveChanges();

                success = true;
            }



            entity.Dispose();

            return(Json(success));
        }
        public JsonResult UpdateBerryPrice(Prices prices)
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();

            string berry = prices.Berry;

            bool success = false;

            Price oldPrice = (from p in entity.Prices
                              where p.Berry == berry
                              select p).FirstOrDefault();

            if (oldPrice != null)
            {
                oldPrice.Berry           = prices.Berry;
                oldPrice.Price_per_litre = prices.Price_Per_Litre;

                entity.SaveChanges();
                success = true;
            }

            entity.Dispose();

            return(Json(success));
        }
        public JsonResult GetBerryValues(string name)
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();

            var pricesList = (from p in entity.Prices
                              where p.Berry == name
                              select p).FirstOrDefault();

            string json = JsonConvert.SerializeObject(pricesList);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public JsonResult PricesTableGet()
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();


            var pricesList = (from p in entity.Prices
                              select p).ToList();

            string json = JsonConvert.SerializeObject(pricesList);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddNewItem(Prices prices)
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();

            bool  success = false;
            Price price   = new Price();

            price.Berry           = prices.Berry;
            price.Price_per_litre = prices.Price_Per_Litre;
            entity.Prices.Add(price);
            entity.SaveChanges();

            entity.Dispose();

            return(Json(success));
        }
        public ActionResult Login(User user)
        {
            KoskenkorvanLuomutilaEntities3 entity = new KoskenkorvanLuomutilaEntities3();

            var usr = entity.Users.Single(u => u.Username == user.Username && u.Password == user.Password);

            if (usr != null)
            {
                Session["Username"] = usr.Username.ToString();
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Käyttäjätunnus tai salasana virheellinen");
            }

            return(RedirectToAction("Index", "Home"));
        }