Ejemplo n.º 1
0
        public async Task <IActionResult> Put([FromBody] Models.Core.Modules data)
        {
            try
            {
                using (var db = new TM.Core.Connection.Oracle())
                {
                    var nd = db.Connection.getUserFromToken(TM.Core.HttpContext.Header("Authorization"));
                    if (nd == null)
                    {
                        return(Json(new { msg = TM.Core.Common.Message.error_token.ToString() }));
                    }
                    var _data = await db.Connection.GetAsync <Models.Core.Modules>(data.id);

                    if (_data != null)
                    {
                        //_data.code = data.code;
                        _data.title         = data.title;
                        _data.required_auth = data.required_auth;
                        _data.alias         = data.alias;
                        _data.url           = data.url;
                        _data.permissions   = data.permissions;
                        _data.orders        = data.orders;
                        _data.descs         = data.descs;
                        _data.contents      = data.contents;
                        _data.updated_by    = nd.ma_nd;
                        _data.updated_at    = DateTime.Now;
                        _data.flag          = data.flag;
                    }
                    await db.Connection.UpdateAsync(_data);

                    return(Json(new { data = _data, msg = TM.Core.Common.Message.success.ToString() }));
                }
            }
            catch (System.Exception) { return(Json(new { msg = TM.Core.Common.Message.danger.ToString() })); }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] Models.Core.Modules data)
        {
            try
            {
                using (var db = new TM.Core.Connection.Oracle())
                {
                    var nd = db.Connection.getUserFromToken(TM.Core.HttpContext.Header("Authorization"));
                    if (nd == null)
                    {
                        return(Json(new { msg = TM.Core.Common.Message.error_token.ToString() }));
                    }
                    if (db.Connection.isExist("Modules", "code", data.code))
                    {
                        return(Json(new { msg = TM.Core.Common.Message.exist.ToString() }));
                    }
                    data.id         = Guid.NewGuid().ToString("N");
                    data.created_by = nd.ma_nd;
                    data.created_at = DateTime.Now;
                    await db.Connection.InsertOraAsync(data);

                    return(Json(new { data = data, msg = TM.Core.Common.Message.success.ToString() }));
                }
            }
            catch (System.Exception) { return(Json(new { msg = TM.Core.Common.Message.danger.ToString() })); }
        }