Beispiel #1
0
        public IActionResult UploadCurses(IFormFile file)
        {
            if (file == null)
            {
                return(StatusCode((int)HttpStatusCode.UnsupportedMediaType, new { response = "file null" }));
            }
            else if (!file.FileName.EndsWith(".json"))
            {
                return(StatusCode((int)HttpStatusCode.UnsupportedMediaType, new { response = ".json required" }));
            }

            using (var reader = new StreamReader(file.OpenReadStream()))
            {
                string result = reader.ReadToEnd();
                if (_timetableConfigService.CreateCourseData(result, User.Identity.Name, file.FileName) == Models.LocalModels.CreationStatus.Created)
                {
                    return(Ok(new { response = "success" }));
                }
            }
            return(StatusCode((int)HttpStatusCode.InternalServerError, new { response = "Something went wrong!" }));
        }