public IEnumerable <Recieved_ammount> Get(int id)
        {
            JalkahoitolaEntities    entities = new JalkahoitolaEntities();
            List <Recieved_ammount> items    = (from o in entities.Recieved_ammounts
                                                where o.ProductId == id
                                                select o).ToList();

            entities.Dispose();
            List <Recieved_ammount> result = new List <Recieved_ammount>();

            foreach (Recieved_ammount item in items)
            {
                Recieved_ammount data = new Recieved_ammount();
                if (item.UnitStock > 0)
                {
                    data.ProductId      = item.ProductId;
                    data.SaapumiseranId = item.SaapumiseranId;
                    data.VendorName     = item.VendorName;
                    data.ExpireDate     = item.ExpireDate;
                    data.Date           = item.Date;
                    data.Price          = item.Price;
                    data.UnitStock      = item.UnitStock;

                    result.Add(data);
                }
            }
            return(result);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Recieved_ammount recieved_ammount = db.Recieved_ammounts.Find(id);

            db.Recieved_ammounts.Remove(recieved_ammount);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "SaapumiseränId,ProductId,Date,ExpireDate,Price,VendorName,LocationCode")] Recieved_ammount recieved_ammount)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recieved_ammount).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Nmae", recieved_ammount.ProductId);
     return(View(recieved_ammount));
 }
        // GET: api/ReduceProduct
        public IEnumerable <Recieved_ammount> Get(int?SaapumiseranId)
        {
            //Query entry from entity
            JalkahoitolaEntities entities      = new JalkahoitolaEntities();
            Recieved_ammount     EntryToModify = (from p in entities.Recieved_ammounts
                                                  where p.SaapumiseranId == SaapumiseranId
                                                  select p).SingleOrDefault();
            int?id = EntryToModify.ProductId;

            //Take the last one and remove
            if (EntryToModify.UnitStock == 1)
            {
                EntryToModify.UnitStock = EntryToModify.UnitStock - 1;
                //EntryToModify = null;
                entities.Recieved_ammounts.Remove(EntryToModify);
                entities.SaveChanges();
            }
            //If there's more than one, just reduce the amount
            if (EntryToModify.UnitStock > 1)
            {
                EntryToModify.UnitStock = EntryToModify.UnitStock - 1;
                entities.SaveChanges();
            }


            //Get updated list from db and return it to client
            List <Recieved_ammount> items = (from o in entities.Recieved_ammounts
                                             where o.ProductId == id
                                             select o).ToList();

            entities.Dispose();
            List <Recieved_ammount> result = new List <Recieved_ammount>();

            foreach (Recieved_ammount item in items)
            {
                Recieved_ammount data = new Recieved_ammount();
                if (item.UnitStock > 0)
                {
                    data.ProductId      = item.ProductId;
                    data.SaapumiseranId = item.SaapumiseranId;
                    data.VendorName     = item.VendorName;
                    data.ExpireDate     = item.ExpireDate;
                    data.Date           = item.Date;
                    data.Price          = item.Price;
                    data.UnitStock      = item.UnitStock;
                    result.Add(data);
                }
            }
            return(result);
        }
        // GET: EditRecievedAmmount/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recieved_ammount recieved_ammount = db.Recieved_ammounts.Find(id);

            if (recieved_ammount == null)
            {
                return(HttpNotFound());
            }
            return(View(recieved_ammount));
        }
        // GET: EditRecievedAmmount/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Recieved_ammount recieved_ammount = db.Recieved_ammounts.Find(id);

            if (recieved_ammount == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Nmae", recieved_ammount.ProductId);
            return(View(recieved_ammount));
        }
        public int Post([FromBody] Recieved_ammount value)
        {
            /*
             * Recieved_ammount testvalue = new Recieved_ammount();
             * testvalue.ProductId = value.ProductId;
             * testvalue.SaapumiseränId = value.SaapumiseränId;
             * testvalue.Date = value.Date;
             * testvalue.ExpireDate = value.ExpireDate;
             * testvalue.Price = value.Price;
             * testvalue.VendorName = value.VendorName;
             * testvalue.LocationCode = value.LocationCode;
             * testvalue.Product = value.Product;
             * testvalue.Stocks = value.Stocks;
             * return testvalue;
             */
            Recieved_ammount     testvalue = new Recieved_ammount();
            JalkahoitolaEntities entities  = new JalkahoitolaEntities();

            entities.Recieved_ammounts.Add(value);
            int result = entities.SaveChanges();

            entities.Dispose();
            return(result);
        }