public AnswerResponseBE InsertProduct(ProductBE IPROD) { AnswerResponseBE AR = new AnswerResponseBE(); MasterProductContext BDMP = new MasterProductContext(); try { int CountProd = 0; CountProd = BDMP.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.Properties = IPROD.Properties; PROD.ReleaseDate = IPROD.ReleaseDate; PROD.ManufacturerEmail = IPROD.ManufacturerEmail; PROD.IdCountry = IPROD.IdCountry; PROD.Cost = IPROD.Cost; PROD.UnitsAvailable = IPROD.UnitsAvailable; PROD.SoldUnits = IPROD.SoldUnits; PROD.StateProduct = IPROD.StateProduct; PROD.ImageProduct = IPROD.ImageProduct; BDMP.Product.Add(PROD); BDMP.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 { BDMP.Dispose(); } return(AR); }
public AnswerResponseBE UpdateProduct(ProductBE UPROD) { AnswerResponseBE AR = new AnswerResponseBE(); MasterProductContext BDMP = new MasterProductContext(); try { Product product = new Product(); product = BDMP.Product.Where(x => x.IdProduct == UPROD.IdProduct).FirstOrDefault(); if (product != null) { product.IdProduct = UPROD.IdProduct; product.NameProduct = UPROD.NameProduct; product.Properties = UPROD.Properties; product.ReleaseDate = UPROD.ReleaseDate; product.ManufacturerEmail = UPROD.ManufacturerEmail; product.IdCountry = UPROD.IdCountry; product.Cost = UPROD.Cost; product.UnitsAvailable = UPROD.UnitsAvailable; product.SoldUnits = UPROD.SoldUnits; product.StateProduct = UPROD.StateProduct; product.ImageProduct = UPROD.ImageProduct; BDMP.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 { BDMP.Dispose(); } return(AR); }
public AnswerResponseBE UpdateUser(UserBE UPUS) { AnswerResponseBE AR = new AnswerResponseBE(); MasterProductContext BDMP = new MasterProductContext(); try { User user = new User(); user = BDMP.User.Where(x => x.IdUser == UPUS.IdUser).FirstOrDefault(); if (user != null) { user.IdUser = UPUS.IdUser; user.NameUser = UPUS.NameUser; user.Photo = UPUS.Photo; BDMP.SaveChanges(); AR.CodeError = 0; AR.DescriptionError = "Se ha actualizado el usuario 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 { BDMP.Dispose(); } return(AR); }
public AnswerResponseBE InsertUser(UserBE IUS) { AnswerResponseBE AR = new AnswerResponseBE(); MasterProductContext BDMP = new MasterProductContext(); try { int CountUser = 0; CountUser = BDMP.User.Where(x => x.IdUser == IUS.IdUser).ToList().Count(); if (CountUser == 0) { User USER = new User(); USER.IdUser = IUS.IdUser; USER.NameUser = IUS.NameUser; USER.Photo = IUS.Photo; BDMP.User.Add(USER); BDMP.SaveChanges(); AR.CodeError = 0; AR.DescriptionError = "Se ha insertado el usuario correctamente"; } else { AR.CodeError = 2; AR.DescriptionError = "El usuario ya existe, por favor verifique la información"; } } catch (Exception EX) { AR.CodeError = 1; AR.DescriptionError = "Hubo un error"; } finally { BDMP.Dispose(); } return(AR); }