Beispiel #1
0
 public IActionResult Create(JsonTextModel json = null)
 {
     if (json.JsonText_ != null)
     {
         var parser = new FhirJsonParser();
         try
         {
             var        res      = parser.Parse <Resource>(json.JsonText_);
             FhirClient client   = new FhirClient(url);
             var        resEntry = client.Create(res);
             json.Status_ = JsonTextModel.CREATED;
         }
         catch (Exception e)
         {
             json.Status_ = JsonTextModel.FAILED;
             return(View(json));
         }
     }
     else
     {
         json         = new JsonTextModel();
         json.Status_ = JsonTextModel.CREATING;
     }
     return(View(json));
 }
        public IActionResult Read(string type, string id, string version = null)
        {
            FhirClient    client = new FhirClient(url);
            String        text   = FhirSerializer.SerializeResourceToJson(client.Get(ResourceIdentity.Build(type, id, version)));
            JsonTextModel m      = new JsonTextModel(type, id, version, text);

            m.Status_ = JsonTextModel.READING;
            return(View(m));
        }
        public IActionResult Edit(JsonTextModel json)
        {
            if (string.IsNullOrWhiteSpace(json.JsonText_))
            {
                return(View(json));
            }
            var parser = new FhirJsonParser();

            try
            {
                var        res      = parser.Parse <Resource>(json.JsonText_);
                FhirClient client   = new FhirClient(url);
                var        resEntry = client.Update(res);
                json.Status_ = JsonTextModel.UPDATED;
            }

            catch (Exception e)
            {
                json.Status_ = JsonTextModel.FAILED;
                return(View(json));
            }
            return(View(json));
        }
 private IActionResult View(JsonTextModel json, Exception e)
 {
     throw new NotImplementedException();
 }
Beispiel #5
0
        public StoreModules()
        {
            this.RequiresAuthentication();

            /*
             * Saves image and its id for specified date. Requires authentication
             */
            Put["/saveimage/date={year}-{month}-{day}"] = parameters =>
            {
                int userid = AuthenticationHelper.GetUserFromApiKey(Request.Headers.Authorization).Id;

                String   imageId = "image" + parameters.day + parameters.month + parameters.year;
                DateTime date    = new DateTime(parameters.year, parameters.month, parameters.day);

                DatabaseAdapter.storeImageId(date, userid, imageId);

                var parser = new MultipartFormDataParser(Request.Body);
                var file   = parser.Files.First();
                using (var fileStream = File.Create("C:\\Users\\g.dzesov\\server\\" + userid + "\\" + imageId + ".png"))
                {
                    file.Data.CopyTo(fileStream);
                }

                return(HttpStatusCode.OK);
            };

            /*
             * Saves video and its id for specified date. Requires authentication
             */
            Put["/savevideo/date={year}-{month}-{day}"] = parameters =>
            {
                int userid = AuthenticationHelper.GetUserFromApiKey(Request.Headers.Authorization).Id;

                String   videoId = "video" + parameters.day + parameters.month + parameters.year;
                DateTime date    = new DateTime(parameters.year, parameters.month, parameters.day);

                DatabaseAdapter.storeVideoId(date, userid, videoId);

                var parser = new MultipartFormDataParser(Request.Body);
                var file   = parser.Files.First();
                using (var fileStream = File.Create("C:\\Users\\g.dzesov\\server\\" + userid + "\\" + videoId + ".mp4"))
                {
                    file.Data.CopyTo(fileStream);
                }

                return(HttpStatusCode.OK);
            };

            /*
             * Saves text for specified date. Requires authentication
             */
            Put["/savetext/date={year}-{month}-{day}"] = parameters =>
            {
                int userid = AuthenticationHelper.GetUserFromApiKey(Request.Headers.Authorization).Id;

                DateTime date = new DateTime(parameters.year, parameters.month, parameters.day);

                String s = Context.Request.Body.ToString();

                JsonTextModel obj = JsonConvert.DeserializeObject <JsonTextModel>(s);

                DatabaseAdapter.storeText(date, userid, obj.text);
                return(0);
            };
        }