コード例 #1
0
        public ApiResponse Update(string shortcut_id, [FromBody] ShortCutModel data)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                data.shortcut = data.shortcut ?? "";
                data.shortcut = data.shortcut.Trim();
                if (string.IsNullOrWhiteSpace(data.shortcut))
                {
                    response.msg += "Shortcut cannot be empty" + shortcut_id;
                }


                data.name = data.name ?? "";
                data.name = data.name.Trim();
                if (string.IsNullOrWhiteSpace(data.name))
                {
                    response.msg += "Name cannot be empty" + shortcut_id;
                }

                var shortcut = _shortcutService.GetById(data.business_id, shortcut_id);
                if (shortcut != null && !string.IsNullOrWhiteSpace(data.name) && !string.IsNullOrWhiteSpace(data.shortcut))
                {
                    shortcut.name     = data.name;
                    shortcut.shortcut = data.shortcut;
                    response.data     = _shortcutService.Create(shortcut);
                    response.ok       = true;
                }
            }
            catch (Exception ex)
            {
                _logService.Create(new Log
                {
                    message  = ex.Message,
                    category = "Shortcut",
                    link     = $"{Request.HttpContext.Request.Scheme}://{Request.HttpContext.Request.Host}{Request.HttpContext.Request.Path}{Request.HttpContext.Request.QueryString}",
                    details  = JsonConvert.SerializeObject(ex.StackTrace),
                    name     = string.Format("Update shortcut: {0}", data.name)
                });
            }

            return(response);
        }