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"));
        }
示例#2
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();
            // }
        }
        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"));
        }
示例#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());
            }
        }
        // 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();
        }
示例#6
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());
        }
        // 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());
        }
示例#8
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());
        }
        public IHttpActionResult deleteProduct(string apiKey, int p)
        {
            try
            {
                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);

                foreach (var inventory in shop.inventories.Where(y => y.product.product_id == p))
                {
                    inventory.is_prod_active = "N";
                    inventory.prod_quant     = 0;
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Ok(-1));
            }

            return(Ok(true));
        }
        public ActionResult AddNewUser()
        {
            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.users.Add(new user
                    {
                        user_id  = Request.Form["user_id"].ToString(),
                        username = Request.Form["username"].ToString(),
                        shop_id  = int.Parse(Request.Form["shop"].ToString().Split('-').First().Trim()),
                        role_id  = Request.Form["role"].ToString(),
                        api_key  = Request.Form["user_id"].ToString(),
                        password = Request.Form["password"].ToString()
                    });

                    if (Request.Form["role"].ToString().Equals("Owner"))
                    {
                        int shop_id = int.Parse(Request.Form["shop"].ToString().Split('-').First().Trim());
                        var shop    = db.shops.First(y => y.shop_id == shop_id);
                        shop.shop_mngr = Request.Form["user_id"].ToString();
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Users"));
                }
            }
            catch (Exception e)
            {
            }
            return(RedirectToAction("Login"));
        }
示例#11
0
        public IHttpActionResult clearSaleInvoicePayment(String apiKey, String invoiceId, double amt)
        {
            sale invoice = null;

            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);

                invoice = db.sales.FirstOrDefault(y => y.sale_id.Equals(invoiceId));

                if (null == invoice)
                {
                    return(Ok(false));
                }

                if (invoice.paid_amt + amt == invoice.total_amt)
                {
                    invoice.is_pmnt_clr = "Y";
                }

                invoice.paid_amt += amt;

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                //ok = false;
            }
            finally { }

            return(Ok(true));
        }
        public ActionResult DeleteUser(String user_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.users.Remove(db.users.FirstOrDefault(y => y.user_id.Equals(user_id)));
                    db.SaveChanges();
                    return(RedirectToAction("Users"));
                }
            }
            catch (Exception e)
            {
            }
            return(RedirectToAction("Login"));
        }
        public ActionResult SaveShopEdit()
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            try
            {
                var    shop_id = int.Parse(Request.Form["shop_id"].ToString());
                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")))
                {
                    var shop = db.shops.FirstOrDefault(y => y.shop_id == shop_id);
                    shop.shope_name = Request.Form["shop_name"].ToString();
                    if (!Request.Form["shop_mng"].ToString().Equals("Select A Manager"))
                    {
                        shop.shop_mngr = Request.Form["shop_mng"].ToString();
                        var user = db.users.First(y => y.user_id.Equals(shop.shop_mngr));
                        user.role_id = "Owner";
                        user.shop_id = shop.shop_id;
                    }

                    shop.phone   = Request.Form["phone"].ToString();
                    shop.address = Request.Form["address"].ToString();
                    db.SaveChanges();
                    return(RedirectToAction("Shops"));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Shops"));
            }
            return(RedirectToAction("Login"));
        }
        public ActionResult SaveUserEdit()
        {
            SMS_DBEntities1 db = new SMS_DBEntities1();

            try
            {
                var    user_id = Request.Form["user_id"].ToString();
                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")))
                {
                    var user = db.users.FirstOrDefault(y => y.user_id.Equals(user_id));
                    user.username = Request.Form["username"].ToString();
                    user.shop_id  = int.Parse(Request.Form["shop"].Split('-').First());
                    user.role_id  = Request.Form["role"].ToString();
                    user.password = Request.Form["password"].ToString();

                    if (user.role_id.Equals("Owner"))
                    {
                        var shop = db.shops.First(y => y.shop_id == y.shop_id);
                        shop.shop_mngr = user.user_id;
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Users"));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Users"));
            }
            return(RedirectToAction("Login"));
        }
        public IHttpActionResult saleProducts(JSale sale)
        {
            string sale_id = "";

            try
            {
                SMS_DBEntities1 db   = new SMS_DBEntities1();
                var             user = db.users.FirstOrDefault(y => y.api_key.Equals(sale.apiKey));
                if (null == user)
                {
                    return(Ok(sale_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);
                int i         = 1;

                try {
                    var s_sales = shop.sales.Where(y => y.sale_date.Equals(DateTime.Today.Date));
                    if (shop.sales.Count != 0 && null != s_sales && s_sales.Count() != 0)
                    {
                        int num   = s_sales.Max(y => y.sr_no);
                        var sr_no = int.Parse(db.sales.First(y => y.sr_no == num).sale_id.Substring(11)) + 1;
                        sale_id = DateTime.Today.Date.ToString("ddMMyyyy") + shop.shop_id.ToString("000") + sr_no.ToString("000");
                    }
                    else
                    {
                        sale_id = DateTime.Today.Date.ToString("ddMMyyyy") + shop.shop_id.ToString("000") + "001";
                    }
                }
                catch (Exception ex)
                {
                    sale_id = DateTime.Today.Date.ToString("ddMMyyyy") + shop.shop_id.ToString("000") + "001";
                }

                foreach (var product in sale.products)
                {
                    var invObj = inventory.FirstOrDefault(y => y.product_id == product.product_id);
                    if (invObj != null)
                    {
                        if (invObj.prod_quant - product.qty < 0)
                        {
                            return(Ok(-1));
                        }
                        invObj.prod_quant -= product.qty;
                        var isClr = "N";
                        if (i == sale.products.Length)
                        {
                            if (sale.amount_paid == sale.total_amount)
                            {
                                isClr = "Y";
                            }
                            db.sales.Add(new sale
                            {
                                sale_id     = sale_id,
                                sale_date   = DateTime.Today,
                                agent_id    = user.user_id,
                                sale_time   = DateTime.Now.TimeOfDay,
                                total_amt   = sale.total_amount,
                                paid_amt    = sale.amount_paid,
                                discount    = sale.discount,
                                is_pmnt_clr = isClr,
                                shop_id     = shop.shop_id,
                                prod_quant  = (int)product.qty,
                                cust_name   = sale.cust_name,
                                cust_phone  = sale.cust_phone,
                                product_id  = product.product_id,
                                is_invoice  = "Y"
                            });
                        }
                        else
                        {
                            db.sales.Add(new sale
                            {
                                sale_id     = sale_id,
                                sale_date   = DateTime.Today,
                                agent_id    = user.user_id,
                                sale_time   = DateTime.Now.TimeOfDay,
                                total_amt   = product.amount,
                                paid_amt    = product.amount,
                                shop_id     = shop.shop_id,
                                product_id  = product.product_id,
                                prod_quant  = (int)product.qty,
                                cust_name   = sale.cust_name,
                                cust_phone  = sale.cust_phone,
                                is_invoice  = "N",
                                is_pmnt_clr = "N"
                            });
                        }
                    }
                    else
                    {
                        return(Ok(-1));
                    }

                    i++;
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                sale_id = "Error";
            }
            finally { }

            return(Ok(sale_id));
        }
示例#16
0
        public IHttpActionResult purchaseProducts(JPurchase purchase)
        {
            try
            {
                SMS_DBEntities1 db   = new SMS_DBEntities1();
                var             user = db.users.FirstOrDefault(y => y.api_key.Equals(purchase.apiKey));
                if (null == user)
                {
                    return(Ok(-1));
                }
                var shop      = db.shops.FirstOrDefault(y => y.shop_id == user.shop_id);
                var inventory = shop.inventories.ToList();
                int i         = 1;

                List <purchase> purchases = new List <purchase>();

                try
                {
                    if (null != db.purchases.FirstOrDefault(y => y.purch_id == purchase.purch_id))
                    {
                        return(Ok(-1));
                    }
                }
                catch (Exception ex) { }

                foreach (var product in purchase.products)
                {
                    var prod_id      = product.product_id;
                    var brand_id     = -1;
                    var product_type = -1;
                    inventory = shop.inventories.ToList();

                    if (null == inventory.FirstOrDefault(y => y.product.brand_id == product.brand.brand_id) &&
                        null == inventory.FirstOrDefault(y => y.product.brand.brand_name.ToLower().Equals(product.brand.brand_name.ToLower())))
                    {
                        db.brands.Add(new brand {
                            brand_name = product.brand.brand_name
                        });
                        db.SaveChanges();
                        brand_id = db.brands.Where(y => y.brand_name.Equals(product.brand.brand_name)).First(y => y.products.Count == 0).brand_id;
                    }
                    else if (null != inventory.FirstOrDefault(y => y.product.brand.brand_name.ToLower().Equals(product.brand.brand_name.ToLower())))
                    {
                        brand_id = inventory.FirstOrDefault(y => y.product.brand.brand_name.ToLower().Equals(product.brand.brand_name.ToLower())).product.brand_id;
                    }
                    else if (null != db.brands.FirstOrDefault(y => y.brand_id == product.brand.brand_id) &&
                             product.brand.brand_name != null && !product.brand.brand_name.Equals(""))
                    {
                        brand b = db.brands.FirstOrDefault(y => y.brand_id == product.brand.brand_id);
                        b.brand_name = product.brand.brand_name;
                        db.SaveChanges();
                        brand_id = b.brand_id;
                    }
                    if (null == inventory.FirstOrDefault(y => y.product.product_type == product.product_type.type_id) &&
                        null == inventory.FirstOrDefault(y => y.product.product_types.type_name.ToLower().Equals(product.product_type.type_name.ToLower())))
                    {
                        db.product_types.Add(new product_types {
                            type_name = product.product_type.type_name
                        });
                        db.SaveChanges();
                        product_type = db.product_types.Where(y => y.type_name.Equals(product.product_type.type_name)).First(y => y.products.Count == 0).type_id;
                    }
                    else if (null != inventory.FirstOrDefault(y => y.product.product_types.type_name.ToLower().Equals(product.product_type.type_name.ToLower())))
                    {
                        product_type = inventory.FirstOrDefault(y => y.product.product_types.type_name.ToLower().Equals(product.product_type.type_name.ToLower())).product.product_type;
                    }
                    else if (null != db.product_types.FirstOrDefault(y => y.type_id == product.product_type.type_id) &&
                             product.product_type.type_name != null && !product.product_type.type_name.Equals(""))
                    {
                        product_types p = db.product_types.FirstOrDefault(y => y.type_id == product.product_type.type_id);
                        p.type_name = product.product_type.type_name;
                        db.SaveChanges();
                        product_type = p.type_id;
                    }
                    int msr_unit = -1;
                    if (null == inventory.FirstOrDefault(y => y.product.msrmnt_units.sr_no == product.unit_of_msrmnt.sr_no) &&
                        null == inventory.FirstOrDefault(y => y.product.msrmnt_units.description.ToLower().Equals(product.unit_of_msrmnt.description)))
                    {
                        db.msrmnt_units.Add(new msrmnt_units {
                            description = product.unit_of_msrmnt.description
                        });
                        db.SaveChanges();
                        msr_unit = db.msrmnt_units.Where(y => y.description.Equals(product.unit_of_msrmnt.description)).First(y => y.products.Count == 0).sr_no;
                    }
                    else if (null != inventory.FirstOrDefault(y => y.product.msrmnt_units.description.ToLower().Equals(product.unit_of_msrmnt.description)))
                    {
                        msr_unit = inventory.FirstOrDefault(y => y.product.msrmnt_units.description.ToLower().Equals(product.unit_of_msrmnt.description)).product.unit_of_msrmnt;
                    }
                    else
                    {
                        var msmnt_unit = db.msrmnt_units.FirstOrDefault(y => y.sr_no.Equals(product.unit_of_msrmnt.sr_no));
                        msmnt_unit.description = product.unit_of_msrmnt.description;
                        msr_unit = msmnt_unit.sr_no;
                        db.SaveChanges();
                    }

                    if (null == inventory.FirstOrDefault(y => y.product_id == product.product_id) &&
                        null == inventory.FirstOrDefault(y => y.product.product_name.ToLower().Equals(product.product_name.ToLower())))
                    {
                        db.products.Add(new product
                        {
                            product_name   = product.product_name,
                            unit_price     = product.unit_price,
                            unit_of_msrmnt = msr_unit,
                            specs          = product.specs,
                            brand_id       = brand_id,
                            product_type   = product_type
                        });

                        db.SaveChanges();
                        var pros = db.products.Where(y => y.product_name.ToLower().Equals(product.product_name.ToLower())).First(y => y.inventories.Count == 0);
                        prod_id = pros.product_id;
                    }


                    if (0 != product.product_id)
                    {
                        prod_id = product.product_id;
                        var prod = db.products.First(y => y.product_id == product.product_id);
                        prod.product_name = product.product_name;
                        db.SaveChanges();
                    }

                    var invObj = inventory.FirstOrDefault(y => y.product_id == prod_id);
                    if (invObj != null)
                    {
                        invObj.prod_quant += product.qty;
                    }
                    else
                    {
                        db.inventories.Add(new inventory
                        {
                            product_id      = prod_id,
                            shop_id         = shop.shop_id,
                            prod_quant      = product.qty,
                            is_brand_active = "Y",
                            is_prod_active  = "Y"
                        });
                    }

                    foreach (var inv in inventory.Where(y => y.product.brand_id == brand_id))
                    {
                        inv.is_brand_active = "Y";
                    }

                    if (i == purchase.products.Length)
                    {
                        var isClr = "N";
                        if (purchase.amount_paid == purchase.total_amount)
                        {
                            isClr = "Y";
                        }

                        purchases.Add(new purchase
                        {
                            purch_id    = purchase.purch_id,
                            prod_id     = prod_id,
                            dlr_dtls    = purchase.dlr_info,
                            prod_quant  = (int)product.qty,
                            pur_date    = purchase.purch_dtime.Date,
                            pur_time    = purchase.purch_dtime.TimeOfDay,
                            shop_id     = shop.shop_id,
                            agent_id    = user.user_id,
                            is_pmnt_clr = isClr,
                            total_amt   = purchase.total_amount,
                            paid_amt    = purchase.amount_paid,
                            is_invoice  = "Y"
                        });
                    }
                    else
                    {
                        purchases.Add(new purchase
                        {
                            purch_id    = purchase.purch_id,
                            prod_id     = prod_id,
                            prod_quant  = (int)product.qty,
                            pur_date    = purchase.purch_dtime.Date,
                            pur_time    = purchase.purch_dtime.TimeOfDay,
                            shop_id     = shop.shop_id,
                            agent_id    = user.user_id,
                            is_pmnt_clr = "N",
                            is_invoice  = "N"
                        });
                    }


                    i++;
                    db.SaveChanges();
                }

                foreach (var purchase1 in purchases)
                {
                    db.purchases.Add(purchase1);
                }

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Ok(-1));
            }
            finally { }

            return(Ok(purchase.purch_id));
        }