Ejemplo n.º 1
0
 public async Task <bool> DeleteProduct(long productId)
 {
     using (ASMContext db = new ASMContext())
     {
         Database.EntityModels.Product product =
             db.Products.Where(x => x.ProductId == productId).FirstOrDefault();
         if (product != null)
         {
             db.Products.Remove(product);
         }
         return(await db.SaveChangesAsync() >= 1);
     }
 }
Ejemplo n.º 2
0
        public async Task <ProductDto> SaveProduct(ProductDto productDto)
        {
            using (ASMContext db = new ASMContext())
            {
                Database.EntityModels.Product p = db.Products.Where
                                                      (x => x.ProductId == productDto.ProductId).FirstOrDefault();
                if (p == null)
                {
                    p = new Product()
                    {
                        Name             = productDto.Name,
                        Description      = productDto.Description,
                        ProductCode      = productDto.ProductCode,
                        ProductCodeOther = productDto.ProductCodeOther,
                        Barcode          = productDto.Barcode,
                        PackSize         = productDto.PackSize,
                        WebCompanyId     = productDto.WebCompanyId
                    };
                    db.Products.Add(p);
                }
                else
                {
                    p.Name             = productDto.Name;
                    p.Description      = productDto.Description;
                    p.ProductCode      = productDto.ProductCode;
                    p.ProductCodeOther = productDto.ProductCodeOther;
                    p.Barcode          = productDto.Barcode;
                    p.PackSize         = productDto.PackSize;
                    p.WebCompanyId     = productDto.WebCompanyId;
                }
                await db.SaveChangesAsync();

                productDto = await Get(productDto.WebCompanyId, productDto.ProductId);

                return(productDto);
            }
        }