// GET: Admin
        //[HttpPost]
        public ActionResult Shops()
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            String session = "";

            try
            {
                if (null != Session && null != Session["key"])
                {
                    session = Session["key"].ToString();
                }
                if (null != session && null != db.users.FirstOrDefault(y => y.api_key.Equals(session) && y.role_id.Equals("Admin")))
                {
                    return(View(db.shops.ToList()));
                }

                var username = Request.Form["username"].ToString();
                var pass     = Request.Form["password"].ToString();

                if (null != db.users.FirstOrDefault(y => y.user_id.Equals(username) &&
                                                    y.password.Equals(pass) && y.role_id.Equals("Admin")))
                {
                    Session.Add("key", db.users.FirstOrDefault(y => y.user_id.Equals(username) &&
                                                               y.password.Equals(pass)).api_key);
                    var shops = db.shops.ToList();
                    shops.Remove(db.shops.FirstOrDefault(y => y.shope_name.Equals("Admin Shop")));
                    return(View(shops));
                }
            }
            catch (Exception e) { }
            return(RedirectToAction("Login"));
        }
        public ActionResult DeleteShop(int shop_id)
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            try
            {
                String session = "";
                if (null != Session && null != Session["key"])
                {
                    session = Session["key"].ToString();
                }
                if (null != session && null != db.users.FirstOrDefault(y => y.api_key.Equals(session) && y.role_id.Equals("Admin")))
                {
                    db.inventories.RemoveRange(db.inventories.Where(y => y.shop_id == shop_id));
                    db.purchases.RemoveRange(db.purchases.Where(y => y.shop_id == shop_id));
                    db.sales.RemoveRange(db.sales.Where(y => y.shop_id == shop_id));
                    db.users.RemoveRange(db.users.Where(y => y.shop_id == shop_id));
                    db.SaveChanges();
                    db.shops.Remove(db.shops.FirstOrDefault(y => y.shop_id == shop_id));
                    db.SaveChanges();
                    return(RedirectToAction("Shops"));
                }
            }
            catch (Exception e)
            {
            }
            return(RedirectToAction("Login"));
        }
        public ActionResult EditUser(String user_id)
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            String session = "";

            try
            {
                if (null != Session && null != Session["key"])
                {
                    session = Session["key"].ToString();
                }
                if (null != session && null != db.users.FirstOrDefault(y => y.api_key.Equals(session) && y.role_id.Equals("Admin")))
                {
                    var shops = db.shops.ToList();
                    var user  = db.users.FirstOrDefault(y => y.user_id == user_id);
                    shops.Remove(db.shops.First(y => y.shop_id == user.shop_id));
                    shops.Remove(db.shops.FirstOrDefault(y => y.shope_name.Equals("Admin Shop")));
                    ViewBag.shops = shops;
                    if (user.role_id.Equals("Salesman"))
                    {
                        ViewBag.role = "Owner";
                    }
                    else
                    {
                        ViewBag.role = "Salesman";
                    }

                    return(View(user));
                }
            }
            catch (Exception e) { }
            return(RedirectToAction("Login"));
        }
Esempio n. 4
0
        public IHttpActionResult Delete(String apiKey, int id)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                var shops = db.shops.ToList();

                List <string> usernames = new List <string>();
                foreach (var shop in shops)
                {
                    if (shop.shop_id == id)
                    {
                        shops.Remove(shop);
                        db.Entry(shop).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                        return(Ok(new CShop(shop)));
                    }
                }
                return(BadRequest());
            }
            else
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult GetStockReport(string apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                if (null != shop)
                {
                    var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id);
                    if (null != inventory)
                    {
                        var cproducts = new List <CProduct>();
                        foreach (var p in inventory)
                        {
                            var product = db.products.FirstOrDefault(x => x.product_id == p.product_id);
                            if (null != product)
                            {
                                var product_type = db.product_types.FirstOrDefault(x => x.type_id == product.product_type);
                                var brand        = db.brands.FirstOrDefault(x => x.brand_id == product.brand_id);
                                var uom          = db.msrmnt_units.FirstOrDefault(y => y.sr_no == product.unit_of_msrmnt);
                                cproducts.Add(new CProduct(product, product_type, brand, uom, p.prod_quant));
                            }
                        }

                        return(Ok(cproducts));
                    }
                }
            }
            return(BadRequest());
        }
        public ActionResult AddNewShop()
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            try
            {
                String session = "";
                if (null != Session && null != Session["key"])
                {
                    session = Session["key"].ToString();
                }
                if (null != session && null != db.users.FirstOrDefault(y => y.api_key.Equals(session) && y.role_id.Equals("Admin")))
                {
                    db.shops.Add(new shop
                    {
                        shope_name = Request.Form["shop_name"].ToString(),
                        phone      = Request.Form["phone"].ToString(),
                        address    = Request.Form["address"].ToString()
                    });

                    db.SaveChanges();
                    return(RedirectToAction("Shops"));
                }
            }
            catch (Exception e)
            {
            }
            return(RedirectToAction("Login"));
        }
Esempio n. 7
0
        public IHttpActionResult GetAllProducts(String apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop       = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inventory  = db.inventories.Where(x => x.shop_id == shop.shop_id && x.is_prod_active.Equals("Y"));
                var cinventory = new List <CInventory>();
                foreach (inventory i in inventory)
                {
                    var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                    if (null != p)
                    {
                        var type  = db.product_types.FirstOrDefault(y => y.type_id == p.product_type);
                        var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                        var uom   = db.msrmnt_units.FirstOrDefault(y => y.sr_no == p.unit_of_msrmnt);
                        cinventory.Add(new CInventory(i, new CProduct(p, type, brand, uom, 0)));
                    }
                }

                return(Ok(cinventory));
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 8
0
        public IHttpActionResult GetAllBrandsForProductType(String apiKey, int productTypeId)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop      = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id && x.is_brand_active.Equals("Y"));
                var cbrands   = new Dictionary <int, CBrand>();
                var cbrands1  = new List <CBrand>();
                IEnumerable <CBrand> distinctList = null;
                foreach (inventory i in inventory)
                {
                    var p = db.products.FirstOrDefault(y => y.product_id == i.product_id && y.product_type == productTypeId);
                    if (null != p)
                    {
                        var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                        //  if(!cbrands.ContainsKey(brand.brand_id))
                        //    cbrands[brand.brand_id] = new CBrand(brand);
                        if (brand != null)
                        {
                            cbrands1.Add(new CBrand(brand));
                            distinctList = cbrands1.GroupBy(x => x.brand_id).Select(x => x.First());
                        }
                    }
                }

                return(Ok(distinctList));
            }


            return(BadRequest());
        }
Esempio n. 9
0
        public IHttpActionResult GetAllProductTypes(String apiKey)
        {
            var prodTypeList = new List <CProductType>();
            IEnumerable <CProductType> distinctList = null;
            SMS_DBEntities1            db           = new SMS_DBEntities1();
            var user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop       = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inventory  = db.inventories.Where(x => x.shop_id == shop.shop_id);
                var cinventory = new List <CInventory>();
                foreach (inventory i in inventory)
                {
                    var p    = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                    var type = db.product_types.FirstOrDefault(y => y.type_id == p.product_type);
                    prodTypeList.Add(new CProductType(type));
                    // var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                    // cinventory.Add(new CInventory(i, new CProduct(p, type, brand, 0)));
                }

                distinctList = prodTypeList.GroupBy(x => x.type_id).Select(x => x.First());
                db.Dispose();
                return(Ok(distinctList));
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 10
0
        public IHttpActionResult getAllSaleInvoices(String apiKey)
        {
            List <JInvoice> invoices = new List <JInvoice>();

            try
            {
                SMS_DBEntities1 db   = new SMS_DBEntities1();
                var             user = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));
                if (null == user)
                {
                    return(Ok());
                }
                var shop = db.shops.FirstOrDefault(y => y.shop_id == user.shop_id);
                foreach (var sale in shop.sales.GroupBy(x => x.sale_id))
                {
                    invoices.Add(new JInvoice(sale.ToList()));
                }
                return(Ok(invoices));
            }
            catch (Exception ex)
            {
                //ok = false;
            }
            finally { }

            return(Ok());
        }
Esempio n. 11
0
        public IHttpActionResult getInventory(string apiKey)
        {
            var             cproducts = new List <CProduct>();
            SMS_DBEntities1 db        = new SMS_DBEntities1();
            var             user      = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop      = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id && x.is_prod_active.Equals("Y") &&
                                                     x.is_brand_active.Equals("Y"));

                foreach (var i in inventory)
                {
                    var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                    if (null != p)
                    {
                        var type  = db.product_types.FirstOrDefault(y => y.type_id == p.product_type);
                        var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                        var uom   = db.msrmnt_units.FirstOrDefault(y => y.sr_no == p.unit_of_msrmnt);

                        cproducts.Add(new CProduct(p, type, brand, uom, i.prod_quant));
                    }
                }
                IEnumerable <CProduct> list = cproducts.OrderBy(x => x.qty);
                return(Ok(cproducts));
            }
            else
            {
                return(Ok(cproducts));
            }
        }
Esempio n. 12
0
        public IHttpActionResult SearchModel(string apiKey, string model)
        {
            SMS_DBEntities1 db        = new SMS_DBEntities1();
            var             user      = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));
            var             shop      = db.shops.FirstOrDefault(y => y.shop_id == user.shop_id);
            var             inventory = db.inventories.Where(y => y.shop_id == shop.shop_id && !(y.is_brand_active.Equals("N") || y.is_prod_active.Equals("N")));

            var cproducts = new List <CInventory>();

            foreach (var i in inventory)
            {
                var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                if (null != p)
                {
                    var type  = db.product_types.FirstOrDefault(y => y.type_id == p.product_type);
                    var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                    var uom   = db.msrmnt_units.FirstOrDefault(y => y.sr_no == p.unit_of_msrmnt);
                    if (p.product_name.IndexOf(model, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        cproducts.Add(new CInventory(i, new CProduct(p, type, brand, uom, 0)));
                    }
                }
            }
            return(Ok(cproducts));
        }
Esempio n. 13
0
        public IHttpActionResult GetAllModelsForProductTypeAndBrand(String apiKey, int productTypeId, int brandId)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop      = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id && x.is_prod_active.Equals("Y") &&
                                                     x.is_brand_active.Equals("Y"));
                var cbrands   = new Dictionary <int, CBrand>();
                var cproducts = new List <CProduct>();
                IEnumerable <CProduct> distinctList = null;
                foreach (inventory i in inventory)
                {
                    var p = db.products.FirstOrDefault(y => y.product_id == i.product_id && y.product_type == productTypeId && y.brand_id == brandId);
                    if (null != p)
                    {
                        var uom = db.msrmnt_units.FirstOrDefault(y => y.sr_no == p.unit_of_msrmnt);

                        cproducts.Add(new CProduct(p, null, null, uom, 0));
                    }
                }

                return(Ok(cproducts));
            }


            return(BadRequest());
        }
Esempio n. 14
0
        public IHttpActionResult Delete(String apiKey, int id)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));
            //if (user.role_id.Equals("admin"))
            //{

            var shop      = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
            var inventory = db.inventories.Where(x => x.shop_id == shop.shop_id);

            foreach (inventory i in inventory)
            {
                var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                if (null != p && p.product_id == id)
                {
                    //inventory.Remove(shop);
                    db.Entry(p).State = System.Data.Entity.EntityState.Deleted;
                    db.Entry(i).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    return(Ok(new CProduct(p, null, null, null, 0)));
                }
            }
            return(Ok(-1));

            // }
            // else
            // {
            //     return BadRequest();
            // }
        }
        // POST api/values
        public void Post([FromBody] user user)
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            user.api_key = GuidGenerator.GenerateTimeBasedGuid().ToString();
            db.users.Add(user);
            db.SaveChanges();
        }
        // GET api/values
        public IEnumerable <string> GetUsers()
        {
            SMS_DBEntities1 db        = new SMS_DBEntities1();
            var             users     = db.users.ToList();
            List <string>   usernames = new List <string>();

            foreach (var user in users)
            {
                usernames.Add(user.user_id);
            }
            return(usernames.ToArray());
            //return new string[] { "ali", "hassan" };
        }
Esempio n. 17
0
        public IHttpActionResult Post(String apiKey, [FromBody] shop shop)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                db.shops.Add(shop);
                db.SaveChanges();
                return(Ok(new CShop(shop)));
            }

            return(BadRequest());
        }
        public IHttpActionResult Login(String userId, String pswd)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.user_id.Equals(userId) && x.password.Equals(pswd));

            if (user != null)
            {
                return(Ok(new CUser(user)));
            }
            else
            {
                return(Ok(false));
            }
        }
Esempio n. 19
0
        public IHttpActionResult getMeasurementUnits(string apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));
            var             shop = db.shops.FirstOrDefault(y => y.shop_id == user.shop_id);
            HashSet <CUoM>  list = new HashSet <CUoM>();

            foreach (var inventory in shop.inventories)
            {
                list.Add(new CUoM(inventory.product.msrmnt_units));
            }

            return(Ok(list.ToArray()));
        }
        public IHttpActionResult getShop(String apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user != null && user.shop_id != 0)
            {
                return(Ok(new CShop(db.shops.FirstOrDefault(y => y.shop_id == user.shop_id))));
            }
            else
            {
                return(Ok(false));
            }
        }
Esempio n. 21
0
        public IHttpActionResult GetProductsSoldToday(String apiKey)
        {
            DateTime dateToday = DateTime.Now.Date;

            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user && user.role_id.Equals("Owner"))
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                if (shop != null)
                {
                    var productsMap = new Dictionary <int, CProduct>();
                    var cproducts   = new List <CProduct>();
                    IEnumerable <CProduct> distinctList = null;
                    var sales = db.sales.Where(x => x.shop_id == shop.shop_id && DbFunctions.TruncateTime(x.sale_date) == dateToday);
                    foreach (var s in sales)
                    {
                        var product = db.products.FirstOrDefault(x => x.product_id == s.product_id);
                        if (null != product)
                        {
                            var type  = db.product_types.FirstOrDefault(y => y.type_id == product.product_type);
                            var brand = db.brands.FirstOrDefault(y => y.brand_id == product.brand_id);
                            var uom   = db.msrmnt_units.FirstOrDefault(y => y.sr_no == product.unit_of_msrmnt);
                            var cp    = new CProduct(product, type, brand, uom, s.prod_quant);

                            if (!productsMap.ContainsKey(cp.product_id))
                            {
                                productsMap[cp.product_id] = cp;
                            }
                            else
                            {
                                productsMap[cp.product_id].qty += s.prod_quant;
                            }

                            cproducts.Add(cp);
                        }
                    }

                    distinctList = cproducts.GroupBy(x => x.product_id).Select(x => x.First());
                    foreach (var p in distinctList)
                    {
                        p.qty = productsMap[p.product_id].qty;
                    }
                    distinctList = distinctList.OrderByDescending(p => p.qty);
                    return(Ok(distinctList));
                }
            }
            return(BadRequest());
        }
Esempio n. 22
0
        public IHttpActionResult GetShop(String apiKey, String shopName)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                var shop = db.shops.FirstOrDefault(x => x.shope_name.Equals(shopName));

                return(Ok(new CShop(shop)));
            }
            else
            {
                return(BadRequest());
            }
        }
        // GET api/values/5
        public IHttpActionResult Get(string id)
        {
            SMS_DBEntities1 db    = new SMS_DBEntities1();
            var             users = db.users.ToList();

            List <string> usernames = new List <string>();

            foreach (var user in users)
            {
                if (user.user_id.Equals(id))
                {
                    return(Ok(user));
                }
            }
            return(BadRequest());
        }
        public IHttpActionResult GetTodaySale(string apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                if (null != shop)
                {
                    var sales = db.Database.SqlQuery <TodaySale>("select product_id,sum(prod_quant) total_items,sum(isnull(total_amt,0)) total_sale from sales where agent_id = @user and sale_date =CAST(GETDATE() AS DATE) group by product_id;", new SqlParameter("@user", user.user_id)).ToList();

                    return(Ok(sales));
                }
            }
            return(BadRequest());
        }
Esempio n. 25
0
        public IHttpActionResult getProductQuantity(string apiKey, int product)
        {
            var             cproducts = new List <CProduct>();
            SMS_DBEntities1 db        = new SMS_DBEntities1();
            var             user      = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                var inv  = shop.inventories.FirstOrDefault(y => y.product_id == product);
                if (inv != null)
                {
                    return(Ok(inv.prod_quant));
                }
            }

            return(Ok(0));
        }
        public IHttpActionResult GetSalesAmountByMonth(string apiKey)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (null != user)
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == user.shop_id);
                if (null != shop)
                {
                    var sales = db.Database.SqlQuery <SaleByMonth>("select DATEADD(DAY,1,EOMONTH(sale_date,-1)) as date,sum(paid_amt) as saleAmount from sales where shop_id = @shop and sale_date between DATEADD(DAY,-365,GETDATE()) and GETDATE() and is_invoice = 'Y' group by DATEADD(DAY,1,EOMONTH(sale_date,-1))", new SqlParameter("@shop", shop.shop_id)).ToList();
                    List <SaleByMonth> salesWithFillers = new List <SaleByMonth>();

                    for (int i = 11; i >= 0; i--)
                    {
                        int month = DateTime.Today.Month, year = DateTime.Today.Year;

                        if (DateTime.Today.Month - i > 0)
                        {
                            month -= i;
                        }
                        else
                        {
                            year--;
                            month = 12 + (DateTime.Today.Month - i);
                        }

                        var    s       = sales.FirstOrDefault(x => x.date.Month == month);
                        double saleAmt = 0.0;
                        if (null != s)
                        {
                            saleAmt = s.saleAmount;
                        }

                        salesWithFillers.Add(new SaleByMonth {
                            date = new DateTime(year, month, 1), saleAmount = saleAmt
                        });
                    }

                    return(Ok(salesWithFillers));
                }
            }
            return(BadRequest());
        }
Esempio n. 27
0
        public IHttpActionResult Put(String apiKey, int id, [FromBody] shop updatedShop)
        {
            SMS_DBEntities1 db   = new SMS_DBEntities1();
            var             user = db.users.FirstOrDefault(x => x.api_key.Equals(apiKey));

            if (user.role_id.Equals("admin"))
            {
                var shop = db.shops.FirstOrDefault(x => x.shop_id == id);
                if (shop != null)
                {
                    shop.shope_name      = updatedShop.shope_name;
                    shop.shop_mngr       = updatedShop.shop_mngr;
                    db.Entry(shop).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return(Ok(new CShop(shop)));
                }
            }
            return(BadRequest());
        }
Esempio n. 28
0
        public IHttpActionResult SearcProduct(String userId, String product)
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();
            //  IEnumerable<product> products = db.products.Where(x => x.product_name.Equals(product_name));
            var products  = new List <product>();
            var user_id   = userId;
            var user      = db.users.FirstOrDefault(y => y.api_key.Equals(user_id));
            var shop      = db.shops.FirstOrDefault(y => y.shop_id == user.shop_id);
            var inventory = db.inventories.Where(y => y.shop_id == shop.shop_id && !(y.is_brand_active.Equals("N") || y.is_prod_active.Equals("N")));


            //var inventory = db.inventories;



            //foreach (var i in inventory)
            //{
            //    var p = db.products.first(y => y.product_id == i.product_id);
            //    if (db.product_types.first(y=>y.type_id==p.product_type).type_name.equals(product))
            //        products.add(p);

            //}
            // return Ok(products);

            var cproducts = new List <CInventory>();

            foreach (var i in inventory)
            {
                var p = db.products.FirstOrDefault(y => y.product_id == i.product_id);
                if (null != p)
                {
                    var type  = db.product_types.FirstOrDefault(y => y.type_id == p.product_type);
                    var brand = db.brands.FirstOrDefault(y => y.brand_id == p.brand_id);
                    var uom   = db.msrmnt_units.FirstOrDefault(y => y.sr_no == p.unit_of_msrmnt);
                    if (type.type_name.IndexOf(product, 0, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        // The string exists in the original
                        cproducts.Add(new CInventory(i, new CProduct(p, type, brand, uom, 0)));
                    }
                }
            }
            return(Ok(cproducts));
        }
Esempio n. 29
0
        public IHttpActionResult getUsersByShop(string apiKey)
        {
            SMS_DBEntities1 db    = new SMS_DBEntities1();
            List <CUser>    users = new List <CUser>();
            var             user  = db.users.FirstOrDefault(y => y.api_key.Equals(apiKey));

            if (null != user && user.role_id.Equals("admin"))
            {
                var userList = db.users.Where(x => x.shop_id == user.shop_id);
                if (userList != null)
                {
                    foreach (var u in userList)
                    {
                        users.Add(new CUser(u));
                    }
                }
            }
            return(Ok(users));
        }
        // DELETE api/values/5
        public IHttpActionResult Delete(string id)
        {
            SMS_DBEntities1 db    = new SMS_DBEntities1();
            var             users = db.users.ToList();

            List <string> usernames = new List <string>();

            foreach (var user in users)
            {
                if (user.user_id.Equals(id))
                {
                    users.Remove(user);
                    db.Entry(user).State = System.Data.Entity.EntityState.Deleted;
                    db.SaveChanges();
                    return(Ok(user));
                }
            }
            return(BadRequest());
        }