public AnswerResponseBE InsertProduct(ProductBE IPROD) { AnswerResponseBE AR = new AnswerResponseBE(); ProductMasterEntities BDPM = new ProductMasterEntities(); try { int CountProd = 0; CountProd = BDPM.Product.Where(x => x.IdProduct == IPROD.IdProduct).ToList().Count(); if (CountProd == 0) { Product PROD = new Product(); PROD.IdProduct = IPROD.IdProduct; PROD.NameProduct = IPROD.NameProduct; PROD.ReleaseDate = IPROD.ReleaseDate; PROD.Email = IPROD.Email; PROD.IdCountry = IPROD.IdCountry; PROD.Cost = IPROD.Cost; PROD.UnitsAvailable = IPROD.UnitsAvailable; PROD.SoldUnits = IPROD.SoldUnits; PROD.StateProduct = IPROD.StateProduct; BDPM.Product.Add(PROD); BDPM.SaveChanges(); AR.CodeError = 0; AR.DescriptionError = "Se ha insertado el producto correctamente"; } else { AR.CodeError = 2; AR.DescriptionError = "El producto ya existe, por favor verifique la información"; } } catch (Exception EX) { AR.CodeError = 1; AR.DescriptionError = "Hubo un error"; } finally { BDPM.Dispose(); } return(AR); }
public AnswerResponseBE UpdateProduct(ProductBE UPROD) { AnswerResponseBE AR = new AnswerResponseBE(); ProductMasterEntities BDPM = new ProductMasterEntities(); try { Product product = new Product(); product = BDPM.Product.Where(x => x.IdProduct == UPROD.IdProduct).FirstOrDefault(); if (product != null) { product.IdProduct = UPROD.IdProduct; product.NameProduct = UPROD.NameProduct; product.ReleaseDate = UPROD.ReleaseDate; product.Email = UPROD.Email; product.IdCountry = UPROD.IdCountry; product.Cost = UPROD.Cost; product.UnitsAvailable = UPROD.UnitsAvailable; product.SoldUnits = UPROD.SoldUnits; product.StateProduct = UPROD.StateProduct; BDPM.SaveChanges(); AR.CodeError = 0; AR.DescriptionError = "Se ha actualizado el producto correctamente"; } else { AR.CodeError = 2; AR.DescriptionError = "El registro no existe, por favor verifique la información"; } } catch (Exception EX) { AR.CodeError = 1; AR.DescriptionError = "Hubo un error"; } finally { BDPM.Dispose(); } return(AR); }