Exemple #1
0
        public void PopulateDropDownListUserType()
        {
            UserTypeData     data = new UserTypeData();
            List <UserTypes> type = data.Types();

            ddlUserType.DataTextField  = "UserType";
            ddlUserType.DataValueField = "IdUserType";
            ddlUserType.DataSource     = type;
            ddlUserType.DataBind();
        }
Exemple #2
0
        public ActionResult Create([Bind(Include =
                                             "UserTypeName"
                                         )] UserType UserType)
        {
            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = UserTypeData.Add(UserType);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Insert");
                }
            }

            return(View(UserType));
        }
Exemple #3
0
 public static UserTypeData toTypeUser(this MySqlDataReader reader)
 {
     if (reader.HasRows)
     {
         UserTypeData type = new UserTypeData();
         while (reader.Read())
         {
             if (!reader.IsDBNull(0))
             {
                 type.Id               = reader.GetInt32(Define.type_id);
                 type.Name             = reader.GetString(Define.type_name);
                 type.Status           = reader.GetBoolean(Define.type_status);
                 type.DefaultPermision = Permision.Read(reader.GetString(Define.default_permision));
                 type.Icon             = reader.GetString(Define.type_icon);
             }
         }
         return(type);
     }
     return(null);
 }
Exemple #4
0
        public ActionResult DeleteConfirmed(
            Int32?UserTypeID
            )
        {
            UserType UserType = new UserType();

            UserType.UserTypeID = System.Convert.ToInt32(UserTypeID);
            UserType            = UserTypeData.Select_Record(UserType);

            bool bSucess = false;

            bSucess = UserTypeData.Delete(UserType);
            if (bSucess == true)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Can Not Delete");
            }
            return(null);
        }
Exemple #5
0
        // GET: /UserType/Delete/<id>
        public ActionResult Delete(
            Int32?UserTypeID
            )
        {
            if (
                UserTypeID == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            UserType UserType = new UserType();

            UserType.UserTypeID = System.Convert.ToInt32(UserTypeID);
            UserType            = UserTypeData.Select_Record(UserType);

            if (UserType == null)
            {
                return(HttpNotFound());
            }
            return(View(UserType));
        }
Exemple #6
0
        public ActionResult Edit(UserType UserType)
        {
            UserType oUserType = new UserType();

            oUserType.UserTypeID = System.Convert.ToInt32(UserType.UserTypeID);
            oUserType            = UserTypeData.Select_Record(UserType);

            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = UserTypeData.Update(oUserType, UserType);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Update");
                }
            }

            return(View(UserType));
        }
Exemple #7
0
        // GET: /UserType/
        public ActionResult Index(string sortOrder,
                                  String SearchField,
                                  String SearchCondition,
                                  String SearchText,
                                  String Export,
                                  int?PageSize,
                                  int?page,
                                  string command)
        {
            if (command == "Show All")
            {
                SearchField                = null;
                SearchCondition            = null;
                SearchText                 = null;
                Session["SearchField"]     = null;
                Session["SearchCondition"] = null;
                Session["SearchText"]      = null;
            }
            else if (command == "Add New Record")
            {
                return(RedirectToAction("Create"));
            }
            else if (command == "Export")
            {
                Session["Export"] = Export;
            }
            else if (command == "Search" | command == "Page Size")
            {
                if (!string.IsNullOrEmpty(SearchText))
                {
                    Session["SearchField"]     = SearchField;
                    Session["SearchCondition"] = SearchCondition;
                    Session["SearchText"]      = SearchText;
                }
            }
            if (command == "Page Size")
            {
                Session["PageSize"] = PageSize;
            }

            ViewData["SearchFields"]     = GetFields((Session["SearchField"] == null ? "User Type I D" : Convert.ToString(Session["SearchField"])));
            ViewData["SearchConditions"] = Library.GetConditions((Session["SearchCondition"] == null ? "Contains" : Convert.ToString(Session["SearchCondition"])));
            ViewData["SearchText"]       = Session["SearchText"];
            ViewData["Exports"]          = Library.GetExports((Session["Export"] == null ? "Pdf" : Convert.ToString(Session["Export"])));
            ViewData["PageSizes"]        = Library.GetPageSizes();

            ViewData["CurrentSort"]          = sortOrder;
            ViewData["UserTypeIDSortParm"]   = sortOrder == "UserTypeID_asc" ? "UserTypeID_desc" : "UserTypeID_asc";
            ViewData["UserTypeNameSortParm"] = sortOrder == "UserTypeName_asc" ? "UserTypeName_desc" : "UserTypeName_asc";

            dtUserType = UserTypeData.SelectAll();

            try
            {
                if (!string.IsNullOrEmpty(Convert.ToString(Session["SearchField"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchCondition"])) & !string.IsNullOrEmpty(Convert.ToString(Session["SearchText"])))
                {
                    dtUserType = UserTypeData.Search(Convert.ToString(Session["SearchField"]), Convert.ToString(Session["SearchCondition"]), Convert.ToString(Session["SearchText"]));
                }
            }
            catch { }

            var Query = from rowUserType in dtUserType.AsEnumerable()
                        select new UserType()
            {
                UserTypeID     = rowUserType.Field <Int32>("UserTypeID")
                , UserTypeName = rowUserType.Field <String>("UserTypeName")
            };

            switch (sortOrder)
            {
            case "UserTypeID_desc":
                Query = Query.OrderByDescending(s => s.UserTypeID);
                break;

            case "UserTypeID_asc":
                Query = Query.OrderBy(s => s.UserTypeID);
                break;

            case "UserTypeName_desc":
                Query = Query.OrderByDescending(s => s.UserTypeName);
                break;

            case "UserTypeName_asc":
                Query = Query.OrderBy(s => s.UserTypeName);
                break;

            default:      // Name ascending
                Query = Query.OrderBy(s => s.UserTypeID);
                break;
            }

            if (command == "Export")
            {
                GridView  gv = new GridView();
                DataTable dt = new DataTable();
                dt.Columns.Add("User Type I D", typeof(string));
                dt.Columns.Add("User Type Name", typeof(string));
                foreach (var item in Query)
                {
                    dt.Rows.Add(
                        item.UserTypeID
                        , item.UserTypeName
                        );
                }
                gv.DataSource = dt;
                gv.DataBind();
                ExportData(Export, gv, dt);
            }

            int pageNumber = (page ?? 1);
            int?pageSZ     = (Convert.ToInt32(Session["PageSize"]) == 0 ? 5 : Convert.ToInt32(Session["PageSize"]));

            return(View(Query.ToPagedList(pageNumber, (pageSZ ?? 5))));
        }
 public IHttpActionResult GetUserTypes()
 {
     return(Ok(UserTypeData.MapTo(user_repository.GetUserTypes())));
 }