Exemplo n.º 1
0
        [HttpPost("{id?}")] // id is an optional parameter
        public async Task <IActionResult> Post([FromBody] RequestJSON requestJSON)
        {
            string expire = string.Empty;
            string guid   = string.Empty;

            if (RouteData.Values["id"] != null)
            {
                guid = RouteData.Values["id"].ToString();
            }
            else
            {
                guid = _utils.ComputeGuid();
            }
            if (!string.IsNullOrWhiteSpace(requestJSON.expire))
            {
                expire = requestJSON.expire;
            }
            else
            {
                expire = _utils.ComputeExpirationTime();
            }
            RequestJSON request = new RequestJSON
            {
                expire = expire,
                user   = requestJSON.user,
                guid   = guid
            };

            ResponseJSON res = await _data.CreateUpdateAsync(request);

            if (!string.IsNullOrWhiteSpace(res.status))
            {
                return(RedirectToAction("Error", "HandleError"));
            }
            return(Ok(new ApiOkResponse(res)));
        }