public async Task <IActionResult> Edit(int id, [Bind(new string[] { "Full_name,Phone,Password,strRole,id" })] log_in log_in)
 {
     if (id != log_in.id)
     {
         return(NotFound());
     }
     if (base.ModelState.IsValid)
     {
         try
         {
             _context.Update(log_in);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!log_inExists(log_in.id))
             {
                 return(NotFound());
             }
             throw;
         }
         return(RedirectToAction("Index"));
     }
     return(View(log_in));
 }
        public IActionResult Log_in_user(Users users)
        {
            string        pass           = users.Password;
            TokenProvider TokenProviderr = new TokenProvider(_context);
            string        userToken      = TokenProviderr.LoginUser(users.Phone.ToString(), users.Password);

            if (userToken == null)
            {
                base.TempData["Error"] = "Invalid login credentials";
                return(Redirect("~/log_in/Log_in"));
            }
            HttpContext.Session.SetString("JWToken", userToken);
            log_in user_id = _context.Log_in.Where((log_in x) => x.Phone == users.Phone).SingleOrDefault();

            if (user_id.strRole.ToString() == "1")
            {
                HttpContext.Session.SetString("roles", user_id.strRole.ToString());
                HttpContext.Session.SetString("Name", user_id.Full_name);
                HttpContext.Session.SetString("shop_name", user_id.Shop_name);
                log_in constants2 = _context.Log_in.FirstOrDefault((log_in x) => x.strRole == 1);
                HttpContext.Session.SetString("phone", constants2.Phone);
                HttpContext.Session.SetString("id", constants2.id.ToString());
                return(Redirect("~/home/admin"));
            }
            HttpContext.Session.SetString("roles", user_id.strRole.ToString());
            HttpContext.Session.SetString("Name", user_id.Full_name);
            HttpContext.Session.SetString("shop_name", user_id.Shop_name);
            log_in constants = _context.Log_in.FirstOrDefault((log_in x) => x.strRole == 1);

            HttpContext.Session.SetString("id", constants.id.ToString());
            HttpContext.Session.SetString("phone", user_id.Phone);
            return(Redirect("~/home/attendant"));
        }
Esempio n. 3
0
        private IEnumerable <Claim> GetUserClaims(log_in user)
        {
            List <Claim> claims = new List <Claim>();
            Claim        _claim;

            _claim = new Claim(ClaimTypes.Role, user.strRole.ToString());
            claims.Add(_claim);
            _claim = new Claim(ClaimTypes.Name, user.strRole.ToString());
            claims.Add(_claim);
            //_claim = new Claim("User_id", user.User_ID.ToString());
            claims.Add(_claim);

            //claims.Add(_claim);
            //_claim = new Claim("EMAILID", user.strEmail);
            //claims.Add(_claim);
            //_claim = new Claim("PHONE", user.strPhone);
            //claims.Add(_claim);
            //_claim = new Claim(ClaimTypes.Name, user.Full_name);
            //claims.Add(_claim);

            //if (user.Role != "")
            //{
            //    _claim = new Claim(user.Role, user.Role);
            //    claims.Add(_claim);
            //}
            return(claims.AsEnumerable <Claim>());
        }
Esempio n. 4
0
 public ActionResult Registration(log_in user)
 {
     if (ModelState.IsValid)
     {
         using (var db = new login_simpleEntities())
         {
             var    crypt     = new SimpleCrypto.PBKDF2();
             int    size      = crypt.SaltSize;
             var    cryptPass = crypt.Compute(user.pass);
             log_in newUser   = new log_in()
             {
                 email    = user.email,
                 pass     = cryptPass,
                 passsalt = crypt.Salt
             };
             db.log_in.Add(newUser);
             try
             {
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 Debug.Print("Here is the error! " + e.Message);
             }
         }
     }
     return(View());
 }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            log_in log_in = await _context.Log_in.FindAsync(id);

            _context.Log_in.Remove(log_in);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public IActionResult Create()
        {
            log_in user = _context.Log_in.FirstOrDefault();

            if (user == null)
            {
                return(View());
            }
            return(Redirect("~/log_in/log_in"));
        }
        public async Task <IActionResult> Create([Bind(new string[] { "Full_name,Shop_name,Phone,Password,strRole,id" })] log_in log_in)
        {
            if (base.ModelState.IsValid)
            {
                _context.Add(log_in);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Log_in"));
            }
            return(RedirectToAction("log_in"));
        }
        public async Task <IActionResult> Details(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }
            log_in log_in = await _context.Log_in.FirstOrDefaultAsync((log_in m) => (int?)m.id == id);

            if (log_in == null)
            {
                return(NotFound());
            }
            return(View(log_in));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(NotFound());
            }
            log_in log_in = await _context.Log_in.FindAsync(id);

            if (log_in == null)
            {
                return(NotFound());
            }
            return(View(log_in));
        }
Esempio n. 10
0
        public ActionResult Login(log_in user)
        {
            if (ValidPass(user.email, user.pass))
            {
                FormsAuthentication.SetAuthCookie(user.email, false);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "login failure");
            }

            return(View());
        }
Esempio n. 11
0
        private IEnumerable <Claim> GetUserClaims(log_in user)
        {
            List <Claim> claims = new List <Claim>();
            Claim        _claim;

            _claim = new Claim(ClaimTypes.Name, user.Full_name.ToString());
            claims.Add(_claim);
            _claim = new Claim(ClaimTypes.Role, user.strRole.ToString());
            claims.Add(_claim);
            _claim = new Claim("user_id", user.Phone.ToString());
            _claim = new Claim("roles", user.strRole.ToString());
            claims.Add(_claim);

            return(claims.AsEnumerable <Claim>());
        }
Esempio n. 12
0
        public IActionResult add_new_attendant(String Full_name, String Phone)
        {
            //LETS JOIN TABLES



            var check_if_item_exists1 = _context.Log_in.SingleOrDefault(x => x.Phone == Phone);

            if (check_if_item_exists1 != null)
            {
                TempData["popup"] = "2";
                //TempData["popup"] = "2";
                //TempData["popup"] = "Successfully working!";
                TempData["message"] = Full_name + " already exists in the system!";
                return(Redirect("~/home/admin"));
            }
            else
            {
                var shop = _context.Log_in.FirstOrDefault(x => x.strRole == 1);

                log_in add_new_attendant = new log_in
                {
                    Full_name = Full_name,
                    Phone     = Phone,
                    Password  = Phone,
                    Shop_name = shop.Shop_name,
                    strRole   = 2,
                };
                _context.Add(add_new_attendant);
                _context.SaveChanges();

                TempData["popup"] = "1";
                //TempData["popup"] = "2";
                //TempData["popup"] = "Successfully working!";
                TempData["message"] = Full_name + " successfully added to the list!";
            }

            return(Redirect("~/home/admin"));
        }
Esempio n. 13
0
        public IActionResult admin(log_in log, [Optional] String date)
        {
            ViewBag.supliers_count = _context.Supliers.Count();

            List <Suppliers> x = new List <Suppliers>();

            //bind dropdown
            x = _context.Supliers.ToList();
            x.Insert(0, new Suppliers {
                id = 0, Company_name = "--Select supplier--"
            });
            ViewBag.Drop_sulier = x;

            expiries_set();
            //LETS CALCULATE SHOP NET WORTH
            var   get_all = _context.Shop_items.Where(x => x.Quantity > 0);
            int   i, j;
            float sum = 0, total;

            j = get_all.Count();
            foreach (var item in get_all)
            {
                sum = sum + (item.Quantity * item.Item_price);
                ViewBag.Net_worth = sum;
            }

            DateTime _date;
            string   day;

            //SOLD ITEMS FOR TODAY
            List <sold_items>     list_of_sold    = _context.sold_items.Where(x => x.DateTime == today).ToList();
            List <shop_items>     list_of_brandss = _context.Shop_items.ToList();
            List <join_sold_item> joinList1       = new List <join_sold_item>();
            var results1 = (from pd in list_of_sold
                            join od in list_of_brandss on pd.Item_id equals od.id
                            select new
            {
                pd.DateTime,
                pd.quantity_sold,
                pd.Total_cash_made,
                od.Item_price,
                od.Item_name,
                pd.Total_Cost_cash,
                pd.id,
                pd.Item_id
            }).ToList();

            foreach (var item in results1)
            {
                join_sold_item JoinObject = new join_sold_item();

                JoinObject.Item_name  = item.Item_name;
                JoinObject.Item_price = item.Item_price;

                JoinObject.DateTime        = item.DateTime;
                JoinObject.quantity_sold   = item.quantity_sold;
                JoinObject.Total_cash_made = item.Total_cash_made;

                JoinObject.Item_price      = item.Item_price;
                JoinObject.Item_name       = item.Item_name;
                JoinObject.Total_Cost_cash = item.Total_Cost_cash;
                JoinObject.Item_id         = item.Item_id.ToString();
                JoinObject.id = item.id;
                joinList1.Add(JoinObject);
            }
            var JoinListToViewbag1 = joinList1.ToList();

            ViewBag.JoinList1 = JoinListToViewbag1;
            if (date == null)
            {
                //SOLD ITEMS FOR THE FIRST MODAL
                List <sold_items> list_of_sold_second = _context.sold_items.ToList();

                List <shop_items>     list_of_brands_second = _context.Shop_items.ToList();
                List <join_sold_item> joinList_second       = new List <join_sold_item>();
                var results_second = (from pd in list_of_sold_second
                                      join od in list_of_brands_second on pd.Item_id equals od.id
                                      select new
                {
                    pd.DateTime,
                    pd.quantity_sold,
                    pd.Total_cash_made,
                    od.Item_price,
                    od.Item_name,
                    pd.Total_Cost_cash
                }).ToList();

                foreach (var item in results_second)
                {
                    join_sold_item JoinObject_second = new join_sold_item();

                    JoinObject_second.Item_name       = item.Item_name;
                    JoinObject_second.Item_price      = item.Item_price;
                    JoinObject_second.Total_Cost_cash = item.Total_Cost_cash;

                    JoinObject_second.DateTime        = item.DateTime;
                    JoinObject_second.quantity_sold   = item.quantity_sold;
                    JoinObject_second.Total_cash_made = item.Total_cash_made;
                    JoinObject_second.Item_price      = item.Item_price;
                    JoinObject_second.Item_name       = item.Item_name;
                    joinList_second.Add(JoinObject_second);
                }
                var JoinListToViewbag_second = joinList_second.ToList();
                ViewBag.JoinList12 = JoinListToViewbag_second;
            }
            else
            {
                _date = DateTime.Parse(date);
                day   = _date.ToString("dd/MM/yyyy");



                //LETS COMPUTE IF COMMAND IS FILTER
                List <sold_items> list_of_sold_third = _context.sold_items.Where(x => x.DateTime == day).ToList();

                List <shop_items>             list_of_brands_third = _context.Shop_items.ToList();
                List <join_sold_ite_filtered> joinList_third       = new List <join_sold_ite_filtered>();
                var results_third = (from pd in list_of_sold_third
                                     join od in list_of_brands_third on pd.Item_id equals od.id
                                     select new
                {
                    pd.DateTime,
                    pd.quantity_sold,
                    pd.Total_cash_made,
                    od.Item_price,
                    od.Item_name,
                }).ToList();

                foreach (var item in results_third)
                {
                    join_sold_ite_filtered JoinObject_third = new join_sold_ite_filtered();

                    JoinObject_third.Item_name       = item.Item_name;
                    JoinObject_third.DateTime        = item.DateTime;
                    JoinObject_third.quantity_sold   = item.quantity_sold;
                    JoinObject_third.Total_cash_made = item.Total_cash_made;
                    JoinObject_third.Item_price      = item.Item_price;
                    JoinObject_third.Item_name       = item.Item_name;
                    joinList_third.Add(JoinObject_third);
                }
                var JoinListToViewbag_third = joinList_third.ToList();
                var count       = joinList_third.Count();
                var sum_of_cash = joinList_third.Sum(x => x.Total_cash_made);
                TempData["popup"] = 4;
                //TempData["popup"] = "2";
                //TempData["popup"] = "Successfully working!";
                TempData["message"] = count + " records found totaling to Ksh. " + sum_of_cash;
                TempData["total"]   = sum_of_cash;


                ViewBag.JoinList_general_third = JoinListToViewbag_third;
            }
            ViewBag.allBrands   = _context.Shop_items.Where(x => x.Quantity > 0).ToList();
            ViewBag.allBrands_0 = _context.Shop_items.ToList();
            ViewBag.id          = HttpContext.Session.GetString("id");

            ViewBag.count_below = _context.Shop_items.Count(x => x.Quantity <= 0);
            ViewBag.to_restock  = _context.Shop_items.Where(x => x.Quantity <= 0);
            ViewBag.count_all   = _context.Shop_items.Sum(x => x.Quantity);
            var sold = _context.sold_items.ToList();

            if (sold.Count() == 0)
            {
                ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold);
            }
            else
            {
                ViewBag.sold = _context.sold_items.Where(x => x.DateTime == today).Sum(x => x.quantity_sold);
            }

            ViewBag.sold_general = _context.sold_items;
            ViewBag.shop_name    = HttpContext.Session.GetString("shop_name");
            ViewBag.name         = HttpContext.Session.GetString("Name");
            ViewBag.id           = HttpContext.Session.GetString("id");
            var phone = HttpContext.Session.GetString("phone");
            //RESTOCKING ITEMS HISTORY
            List <Restock_history> list_of_restocked = _context.Restock_history.ToList();
            List <shop_items>      list_of_brands    = _context.Shop_items.ToList();
            List <join_tables>     joinList          = new List <join_tables>();
            var shop_items   = _context.Shop_items;
            var restock_item = _context.Restock_history;
            var results      = (from pd in list_of_restocked
                                join od in list_of_brands on pd.Item_id equals od.id
                                select new
            {
                pd.Date_restock,
                pd.Prev_quantity,
                pd.new_quanity,
                od.Item_name,
                od.Item_price,
                pd.quantity,
                od.id,
                pd.Supplier,
            }).ToList();

            foreach (var item in results)
            {
                join_tables JoinObject = new join_tables();
                JoinObject.Item_id       = item.id.ToString();
                JoinObject.Item_name     = item.Item_name;
                JoinObject.Item_price    = item.Item_price;
                JoinObject.new_quanity   = item.new_quanity;
                JoinObject.Prev_quantity = item.Prev_quantity;
                JoinObject.quantity      = item.quantity;
                JoinObject.Supplier      = item.Supplier;
                JoinObject.Date_restock  = item.Date_restock;
                joinList.Add(JoinObject);
            }
            var JoinListToViewbag = joinList.ToList();

            ViewBag.JoinList = JoinListToViewbag;
            //TempData["message"] = "success you have deleted the attendant successfully!";
            //GETTING ALL BRANDS
            ViewBag.allBrands = _context.Shop_items.ToList();
            // GETTING ALL ATTENDANTS
            //var phone = @User.Claims.FirstOrDefault(c => c.Type == "User_id").Value;
            ViewBag.all_attendants = _context.Log_in.Where(item => item.strRole == 2).ToList();
            //var getting_quanity = _context.Shop_items.FirstOrDefault();
            //ViewBag.stock=getting_quanity.
            var count_brand = _context.Shop_items.Count();

            var count_below = _context.Shop_items.Where(x => x.Quantity < 0).Count();

            if (count_below == null)
            {
                ViewBag.count_below = 0;
            }
            else
            {
                ViewBag.count_below = count_below;
            }
            //ViewBag.manager_name = _context.Log_in.Where(item=>item.id.ToString()==phone).ToList();
            //TempData["popup"] = "2";

            return(View());
        }