Beispiel #1
0
        public IHttpActionResult PostShop_sProduct(Shop_sProduct shop_sProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ShopProductsBLL.Add(shop_sProduct);

            try
            {
                Global.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (Shop_sProductExists(shop_sProduct.productCode))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = shop_sProduct.productCode }, shop_sProduct));
        }
Beispiel #2
0
        public IHttpActionResult PutShop_sProduct(long id, Shop_sProduct shop_sProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != shop_sProduct.productCode)
            {
                return(BadRequest());
            }

            ShopProductsBLL.Entry(shop_sProduct);

            try
            {
                Global.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Shop_sProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
 public static void Entry(Shop_sProduct shopProducts)
 {
     using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
     {
         db.Entry(shopProducts).State = EntityState.Modified;
     }
 }
 public static void Add(Shop_sProduct shopProducts)
 {
     using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
     {
         db.Shop_sProduct.Add(shopProducts);
     }
 }
 public static ShopProductsDTO DALToDTO(Shop_sProduct shopProducts)
 {
     return(new ShopProductsDTO
     {
         productCode = shopProducts.productCode,
         shopCode = shopProducts.shopCode,
         price = shopProducts.price,
         duration = shopProducts.duration,
         status = shopProducts.status
     });
 }
Beispiel #6
0
        public static ShopProductsDTO Add(ShopProductsDTO shopProducts)
        {
            Shop_sProduct ss = ShopProductsConverter.DTOToDAL(shopProducts);

            using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
            {
                db.Shop_sProduct.Add(ss);
                db.SaveChanges();
            }
            return(ShopProductsConverter.DALToDTO(ss));
        }
Beispiel #7
0
 public static bool DeleteShopProducts(long id)
 {
     using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
     {
         Shop_sProduct shop = db.Shop_sProduct.Find(id);
         if (shop == null)
         {
             return(false);
         }
         db.Shop_sProduct.Remove(shop);
         db.SaveChanges();
     }
     return(true);
 }
Beispiel #8
0
        public static ShopProductsDTO DALToDTO(Shop_sProduct shopProduct)
        {
            using (GetCoffeeDBEntities db = new GetCoffeeDBEntities())
            {
                Product  p = db.Products.FirstOrDefault(pr => pr.code == shopProduct.productCode);
                Category c = db.Categories.FirstOrDefault(ct => ct.code == p.categoryCode);

                return(new ShopProductsDTO
                {
                    Code = shopProduct.code,
                    productCode = shopProduct.productCode,
                    shopCode = shopProduct.shopCode,
                    price = shopProduct.price,
                    duration = shopProduct.duration,
                    status = shopProduct.status,
                    name = p.name,
                    categoryName = c.name
                });
            }
        }