public List <Product> GetProducts() { SwarnaContext swarnacontext = new SwarnaContext(); List <Product> products = new List <Product>(); products = swarnacontext.Products.ToList(); return(products); }
public Product AddProduct(Product prod) { using (var swarnacontext = new SwarnaContext()) { swarnacontext.Products.Add(prod); swarnacontext.SaveChanges(); return(prod); } }
public static bool Login(string username, string password) { using (SwarnaContext entities = new SwarnaContext()) { return(entities.Users.Any(user => user.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && user.Password == password)); } }
public Product DeleteProduct(int id) { SwarnaContext swarnacontext = new SwarnaContext(); Product product = swarnacontext.Products.Find(id); if (product == null) { //return NotFound(); } swarnacontext.Products.Remove(product); swarnacontext.SaveChanges(); return(product); }
public void UpdateProduct(int id, Product product) { using (var swarnacontext = new SwarnaContext()) { swarnacontext.Entry(product).State = EntityState.Modified; try { swarnacontext.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { //return NotFound(); } else { throw; } } } }
// GET: api/Employees public HttpResponseMessage GetEmployees() { //return db.Employees; string username = Thread.CurrentPrincipal.Identity.Name; using (SwarnaContext entities = new SwarnaContext()) { var gender = entities.Employees.Where(x => x.EmpId == entities.Users.Where(y => y.Username == username).FirstOrDefault().EmpId).FirstOrDefault().Gender; switch (gender) { case "male": return(Request.CreateResponse(HttpStatusCode.OK, entities.Employees.Where(e => e.Gender.ToLower() == "male").ToList())); case "female": return(Request.CreateResponse(HttpStatusCode.OK, entities.Employees.Where(e => e.Gender.ToLower() == "female").ToList())); default: return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } }
private bool ProductExists(int id) { SwarnaContext swarnacontext = new SwarnaContext(); return(swarnacontext.Products.Count(e => e.Id == id) > 0); }