Beispiel #1
0
        public ProductGroup Post([FromBody] ProductGroup value)
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();

            entities.ProductGroups.Add(value);
            entities.SaveChanges();
            entities.Dispose();
            return(value);
        }
Beispiel #2
0
        // GET: Products
        public ActionResult Index1()
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();
            List <Product>       model    = entities.Products.ToList();

            entities.Dispose();

            return(View(model));
        }
Beispiel #3
0
        // GET: api/ProductCount/5
        public int?Get(int id)
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();
            List <int?>          items    = (from o in entities.Recieved_ammounts
                                             where o.ProductId == id
                                             select o.UnitStock).ToList();

            entities.Dispose();
            return(items.Sum());
        }
        // 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: api/RemoveProduct/5
        public int Get(int?id)
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();
            List <int?>          items    = (from o in entities.Recieved_ammounts
                                             where o.ProductId == id
                                             select o.UnitStock).ToList();

            if (items.Sum() == 0 || items.Sum() == null)
            {
                Product ProductToBeRemoved = (from o in entities.Products
                                              where o.ProductId == id
                                              select o).First();
                entities.Products.Remove(ProductToBeRemoved);
                entities.SaveChanges();
            }

            entities.Dispose();
            return(1);
        }
        // GET: api/RemoveProductGroup

        //  [HttpGet]
        public int Get(int id)
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();

            int items = (from p in entities.Products
                         where p.GroupId == id
                         select p).Count();

            if (items == 0)
            {
                ProductGroup ProductGroupToBeRemoved = (from p in entities.ProductGroups
                                                        where p.GroupId == id
                                                        select p).First();
                entities.ProductGroups.Remove(ProductGroupToBeRemoved);
                entities.SaveChanges();
            }

            entities.Dispose();
            return(items);
        }
        public IEnumerable <Product> Get(string id)
        {
            //id = "Nitriili";
            JalkahoitolaEntities entities = new JalkahoitolaEntities();
            List <Product>       items    = (from o in entities.Products
                                             where o.Nmae == id
                                             select o).ToList();

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

            foreach (Product item in items)
            {
                Product data = new Product();
                data.Nmae          = item.Nmae;
                data.Quantity      = item.Quantity;
                data.UnitOfMeasure = item.UnitOfMeasure;
                result.Add(data);
            }

            return(result);
        }
        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);
        }
        // POST: api/Product
        public Product Post([FromBody] Product value)
        {
            JalkahoitolaEntities entities = new JalkahoitolaEntities();

            /* Testing part
             * Product newProduct = new Product();
             * newProduct.Nmae = value.Nmae;
             * newProduct.Description = value.Description;
             * newProduct.Quantity = value.Quantity;
             * newProduct.UnitOfMeasure = value.UnitOfMeasure;
             * newProduct.GroupId = value.GroupId;
             * newProduct.Entery_Date = value.Entery_Date;
             * newProduct.Expire = value.Expire;
             * newProduct.Person_Name = value.Person_Name;
             * entities.Products.Add(newProduct);
             * entities.SaveChanges();
             * entities.Dispose();
             * return newProduct;
             */
            entities.Products.Add(value);
            entities.SaveChanges();
            entities.Dispose();
            return(value);
        }