public string AddEmployee(Product Emp) { if (Emp != null) { using (ProductsDbEntities dataContext = new ProductsDbEntities()) { dataContext.Products.Add(Emp); dataContext.SaveChanges(); return "Employee Updated"; } } else { return "Invalid Employee"; } }
public string UpdateEmployee(Product Prod) { if (Prod != null) { using (ProductsDbEntities dataContext = new ProductsDbEntities()) { int no = Convert.ToInt32(Prod.Id); var productList = dataContext.Products.Where(x => x.Id == no).FirstOrDefault(); productList.Name = Prod.Name; productList.Price = Prod.Price; productList.Description = Prod.Description; productList.Image = Prod.Image; dataContext.SaveChanges(); return "Employee Updated"; } } else { return "Invalid Employee"; } }
public string DeleteEmployee(Product Emp) { if (Emp != null) { using (ProductsDbEntities dataContext = new ProductsDbEntities()) { int no = Convert.ToInt32(Emp.Id); var employeeList = dataContext.Products.Where(x => x.Id == no).FirstOrDefault(); dataContext.Products.Remove(employeeList); dataContext.SaveChanges(); return "Employee Deleted"; } } else { return "Invalid Employee"; } }