Example #1
0
        public ActionResult Usermanager(FormCollection collection)
        {
            if (Session["Quantri-website-Quantrivien"] == null)
            {
                Response.Redirect("/");
            }
            if (collection["warning"].ToString() == "")
            {
                TempData["erroruser"]   = "******";
                TempData["successuser"] = null;
                ViewBag.UserList        = accountContext._9d_users.Where(c => c.user_id == 0).ToList();
                return(View());
            }

            if (Convert.ToInt32(collection["usertype"].ToString()) == 2)
            {
                using (var db = new DataAccountContentDataContext())
                {
                    db._9d_users
                    .Where(x => x.telephone == collection["userid"].ToString())
                    .ToList()
                    .ForEach(a =>
                    {
                        a.status  = true;
                        a.message = collection["warning"].ToString();
                    });

                    try
                    {
                        db.SubmitChanges();
                        TempData["erroruser"]   = null;
                        TempData["successuser"] = "******";
                        if (Convert.ToInt32(collection["usertype"].ToString()) == 1)
                        {
                            ViewBag.UserList = accountContext._9d_users.Where(c => c.user_name == collection["usertype"].ToString()).ToList();
                            return(View());
                        }
                        else if (Convert.ToInt32(collection["usertype"].ToString()) == 2)
                        {
                            ViewBag.UserList = accountContext._9d_users.Where(c => c.telephone == collection["userid"].ToString()).ToList();
                        }
                        return(View());
                    }
                    catch (Exception)
                    {
                        TempData["erroruser"]   = "******";
                        TempData["successuser"] = null;
                        if (Convert.ToInt32(collection["usertype"].ToString()) == 1)
                        {
                            ViewBag.UserList = accountContext._9d_users.Where(c => c.user_name == collection["usertype"].ToString()).ToList();
                            return(View());
                        }
                        else if (Convert.ToInt32(collection["usertype"].ToString()) == 2)
                        {
                            ViewBag.UserList = accountContext._9d_users.Where(c => c.telephone == collection["userid"].ToString()).ToList();
                        }
                        return(View());
                    }
                }
            }
            else
            {
                _9d_user us = accountContext._9d_users.Where(c => c.user_name == collection["userid"].ToString()).FirstOrDefault();
                us.status  = true;
                us.message = collection["warning"].ToString();
                try
                {
                    accountContext.SubmitChanges();
                    TempData["erroruser"]   = null;
                    TempData["successuser"] = "******";
                    if (Convert.ToInt32(collection["usertype"].ToString()) == 1)
                    {
                        ViewBag.UserList = accountContext._9d_users.Where(c => c.user_name == collection["usertype"].ToString()).ToList();
                        return(View());
                    }
                    else if (Convert.ToInt32(collection["usertype"].ToString()) == 2)
                    {
                        ViewBag.UserList = accountContext._9d_users.Where(c => c.telephone == collection["userid"].ToString()).ToList();
                    }
                    return(View());
                }
                catch (Exception)
                {
                    TempData["erroruser"]   = "******";
                    TempData["successuser"] = null;
                    if (Convert.ToInt32(collection["usertype"].ToString()) == 1)
                    {
                        ViewBag.UserList = accountContext._9d_users.Where(c => c.user_name == collection["usertype"].ToString()).ToList();
                        return(View());
                    }
                    else if (Convert.ToInt32(collection["usertype"].ToString()) == 2)
                    {
                        ViewBag.UserList = accountContext._9d_users.Where(c => c.telephone == collection["userid"].ToString()).ToList();
                    }
                    return(View());
                }
            }
        }