コード例 #1
0
        public IHttpActionResult Post([FromBody] Request <TreeModel> req)
        {
            Response <Dictionary> rsp = new Response <Dictionary>();

            try
            {
                TreeModel tree = req.Data as TreeModel;

                Dictionary model = null;

                UserInfo user = _user.GetCurrentUser();
                if (user == null)
                {
                    return(base.Redirect("/User/Login#/Login"));
                }

                if (string.IsNullOrEmpty(tree.nodeId))
                {
                    model = new Dictionary();
                    string ID = Guid.NewGuid().ToString();
                    model.nodeId              = ID;
                    model.DictionCategory     = tree.category;
                    model.DictionCategoryName = tree.category;
                    model.CreateUser          = user.LoginName;
                    model.CreateDate          = DateTime.Now;
                    model.UpdateUser          = user.LoginName;
                    model.UpdateDate          = DateTime.Now;
                    model.parentId            = tree.parentId == null ? "0" : tree.parentId;
                    model.text   = tree.text;
                    model.value  = tree.value;
                    model.Remark = "";
                    _dictionary.AddDictionary(model);
                }
                else
                {
                    model = _dictionary.GetDictionaryById(tree.nodeId);
                    if (model == null)
                    {
                        return(NotFound());
                    }
                    model.UpdateDate = DateTime.Now;
                    model.UpdateUser = user.LoginName;
                    model.text       = tree.text;
                    model.value      = tree.value;
                    _dictionary.EditDictionary(model);
                }
                rsp.Data = model;
                return(Ok(rsp));
            }
            catch (Exception ex)
            {
                LogService.WriteErrorLog("DictionaryController[Post]", ex.ToString());
                return(BadRequest(ex.ToString()));
            }
        }