Пример #1
0
        public List <Product> GetProducts()
        {
            SwarnaContext  swarnacontext = new SwarnaContext();
            List <Product> products      = new  List <Product>();

            products = swarnacontext.Products.ToList();
            return(products);
        }
Пример #2
0
 public Product AddProduct(Product prod)
 {
     using (var swarnacontext = new SwarnaContext())
     {
         swarnacontext.Products.Add(prod);
         swarnacontext.SaveChanges();
         return(prod);
     }
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
 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;
             }
         }
     }
 }
Пример #6
0
        // 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));
                }
            }
        }
Пример #7
0
        private bool ProductExists(int id)
        {
            SwarnaContext swarnacontext = new SwarnaContext();

            return(swarnacontext.Products.Count(e => e.Id == id) > 0);
        }