Esempio n. 1
0
        public ActionResult CRUDEdit()
        {
            string crudId     = Request.QueryString[NamingCenter.PARAM_KEY_NAME];
            string reGenerate = Request.QueryString["ReGenerate"];
            string id         = Request.QueryString["Id"];
            var    model      = new CRUDEntity();

            if (reGenerate.IsNotNullOrEmpty() && reGenerate.Equals("true"))
            {
                if (crudId.IsNotNullOrEmpty())
                {
                    ViewData[NamingCenter.PARAM_FORM_VIEW_MODE] = Request.QueryString[NamingCenter.PARAM_FORM_VIEW_MODE];
                    var pageGenerator = new PageGenerator()
                    {
                        TableName = crudId
                    };
                    model    = pageGenerator.GetCRUDEntity();
                    model.Id = id;
                }
            }
            else
            {
                if (crudId.IsNotNullOrEmpty())
                {
                    ViewData[NamingCenter.PARAM_FORM_VIEW_MODE] = "Edit";
                    model = DBContext <CRUDEntity> .Instance.FirstOrDefault(o => o.Id.Equals(crudId, StringComparison.OrdinalIgnoreCase));
                }
                else
                {
                    ViewData[NamingCenter.PARAM_FORM_VIEW_MODE] = "Insert";
                }
            }
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult CRUDEdit(CRUDEntity entity)
        {
            var  isInsert = Request.Form[NamingCenter.PARAM_FORM_VIEW_MODE].Equals("Insert");
            bool result   = false;

            if (isInsert)
            {
                if (DBContext <CRUDEntity> .Instance.FirstOrDefault(o => o.Id.Equals(entity.Id, StringComparison.OrdinalIgnoreCase)) != null)
                {
                    throw new FoxOneException("Crud_Id_Exist");
                }
                result = DBContext <CRUDEntity> .Insert(entity);
            }
            else
            {
                result = DBContext <CRUDEntity> .Update(entity);
            }
            return(Json(result));
        }
Esempio n. 3
0
        public CRUDEntity GetCRUDEntity()
        {
            var    mapping     = new TableMapping(Table);
            var    provider    = Dao.Get().Provider;
            string pkName      = "";
            string parentField = "";
            string titleField  = "";
            string sortField   = "";
            var    key         = mapping.Table.Keys.FirstOrDefault();

            if (key != null)
            {
                pkName = key.Name;
            }
            else
            {
                key = mapping.Table.Columns.FirstOrDefault(o => o.Name == "Id");
                if (key != null)
                {
                    pkName = key.Name;
                }
            }
            var key1 = mapping.Table.Columns.FirstOrDefault(o => o.Name.IndexOf("Parent") >= 0);

            if (key1 != null)
            {
                parentField = key1.Name;
            }
            var key2 = mapping.Table.Columns.FirstOrDefault(o => o.Name.Equals("Name"));

            if (key2 != null)
            {
                titleField = key2.Name;
            }
            var key3 = mapping.Table.Columns.FirstOrDefault(o => o.Name.Equals("Rank"));

            if (key3 != null)
            {
                sortField = key3.Name;
            }
            else
            {
                sortField = pkName;
            }
            var entity = new CRUDEntity()
            {
                Id                    = CRUDName,
                PKName                = pkName,
                RentId                = RentId,
                SelectSQL             = provider.CreateSelectStatement(mapping),
                GetOneSQL             = provider.CreateGetOneStatement(mapping),
                InsertSQL             = provider.CreateInsertStatement(mapping),
                UpdateSQL             = provider.CreateUpdateStatement(mapping),
                DeleteSQL             = provider.CreateDeleteStatement(mapping),
                LastUpdateTime        = DateTime.Now,
                TableName             = mapping.Table.Name,
                ValueField            = pkName,
                TitleField            = titleField,
                DefaultSortExpression = sortField,
                ParentField           = parentField
            };

            return(entity);
        }