示例#1
0
        public IHttpActionResult Delete(String apiKey, int id)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));
            //if (user.role_id.Equals("admin"))
            //{

            var shop      = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
            var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id);

            foreach (inventory i in inventory)
            {
                var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                if (null != p && p.product_id == id)
                {
                    //inventory.Remove(shop);
                    db.Entry(p).State = System.Data.Entity.EntityState.Deleted;
                    db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    return(Ok(new CProduct(p, null, null, null, 0)));
                }
            }
            return(Ok(-1));

            // }
            // else
            // {
            //     return BadRequest();
            // }
        }
示例#2
0
        public IHttpActionResult Delete(String apiKey, int id)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                var shops = db.shops.ToList();

                List <string> usernames = new List <string>();
                foreach (var shop in shops)
                {
                    if (shop.shop_id == id)
                    {
                        shops.Remove(shop);
                        db.Entry(shop).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                        return(Ok(new CShop(shop)));
                    }
                }
                return(BadRequest());
            }
            else
            {
                return(BadRequest());
            }
        }
        // DELETE api/values/5
        public IHttpActionResult Delete(string id)
        {
            SMS_DBEntities1 db    = new SMS_DBEntities1();
            var             users = db.users.ToList();

            List <string> usernames = new List <string>();

            foreach (var user in users)
            {
                if (user.user_id.Equals(id))
                {
                    users.Remove(user);
                    db.Entry(user).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    return(Ok(user));
                }
            }
            return(BadRequest());
        }
示例#4
0
        public IHttpActionResult Put(String apiKey, int id, [FromBody] shop updatedShop)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == id);
                if (shop != null)
                {
                    shop.shope_name      = updatedShop.shope_name;
                    shop.shop_mngr       = updatedShop.shop_mngr;
                    db.Entry(shop).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return(Ok(new CShop(shop)));
                }
            }
            return(BadRequest());
        }