public IActionResult ReadText(TextDto dto) { var service = ImplementationFactory.Create(_services, dto.Implementation); var numberOfWords = service.Read(dto.Text); return(Ok("There are " + numberOfWords + " words in the text")); }
public async Task UpdateTextAsync(TextDto vm) { Text text = await _dbContext.FindAsync <Text>(vm.Id); text.ContentDe = vm.ContentDe; text.ContentEn = vm.ContentEn; await _dbContext.SaveChangesAsync(); }
public async Task <Text> Create(TextDto textDto) { var text = _autoMapper.Map <TextDto, Text>(textDto); await _db.Texts.AddAsync(text); await _db.SaveChangesAsync(CancellationToken.None); return(text); }
public TextDto CalculateNumberOfWords(TextDto dto) { _logger.Log(LogLevel.Information, "calculating number of words"); var domain = DtoDomainMapper.ToDomain(dto); _wordService.CalculateNumberOfWords(domain); return(DtoDomainMapper.ToDto(domain)); }
public void InsertText(TextDto text) { using (LiteDatabase db = new LiteDatabase(base.ConnectionString)) { var texts = db.GetCollection <TextDto>("Text"); texts.Insert(text); texts.EnsureIndex(x => x.Name); } }
public async Task <ApiResponse> Update(TextDto textDto) { try { return(new ApiResponse(Status200OK, "Updated text", await _textStore.Update(textDto))); } catch (InvalidDataException dataException) { return(new ApiResponse(Status400BadRequest, "Failed to update text")); } }
public async ValueTask <ActionResult <TextDto> > GetById(string textId) { var text = await _textRepository.FindAsync(textId); if (text == null || text.IsArchived) { return(NotFound()); } return(TextDto.From(text)); }
public async Task <HttpResponseMessage> Import(TextDto fileName) { var fileStream = _fileUploadService.GetFile(fileName.Text); var result = await _importDefectService.ImportDefectsAsync(fileStream); await _fileUploadService.DeleteFileAsync(fileName.Text); return(result.Succeeded ? Request.CreateResponse(HttpStatusCode.OK, $"Number of imported findings for turbine {result.ResultObject}") : Request.CreateErrorResponse(HttpStatusCode.BadRequest, result.Message)); }
public async Task <IActionResult> CreateAsync(TextDto textDto) { if (ModelState.IsValid) { var user = HttpContext.User; await TextPresentationRepository.AddText(textDto, user); ModelState.Clear(); return(View("AddText")); } return(View("AddText", textDto)); }
public async Task <Text> Update(TextDto textDto) { var text = await _db.Texts.SingleOrDefaultAsync(t => t.TextId == textDto.TextId); if (text == null) { throw new InvalidDataException($"Unable to find Text with ID: {textDto.TextId}"); } text = _autoMapper.Map(textDto, text); _db.Texts.Update(text); await _db.SaveChangesAsync(CancellationToken.None); return(text); }
public async Task <JsonResult> UpdateText([FromBody] TextDto dto) { await _textService.UpdateTextAsync(dto); return(Json(OkReturnString)); }
// POST: api/clinicinstrumentaddcontroller public IHttpActionResult PostClinicInstrumentAdd() { if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var httpRequest = HttpContext.Current.Request; var clinic_Id = httpRequest.Form["clinicId"]; var instrument_Id = httpRequest.Form["instrumentId"]; var text = httpRequest.Form["description"]; string msg = ""; if (clinic_Id == null && instrument_Id == null) { msg = "请选择要添加的科室与操作器械关联"; } int clinicId = int.Parse(clinic_Id); int instrumentId = int.Parse(instrument_Id); var clinicToAdd = _context.Clinics.Find(clinicId); _context.Entry(clinicToAdd).Collection(u => u.Instruments); bool flag = true; foreach (Instrument i in clinicToAdd.Instruments) { if (i.Id == instrumentId) { msg = "此科室与操作器械关联已存在!"; flag = false; } } if (flag) { foreach (Instrument i in clinicToAdd.Instruments) { _context.Entry(i).Collection(u => u.Texts); _context.Entry(i).Collection(u => u.Pictures); _context.Entry(i).Collection(u => u.Videos); } var instrumentToAdd = _context.Instruments.Find(instrumentId); var PostFileName = clinicToAdd.Name + "_" + instrumentToAdd.Name; TextDto t = new TextDto(); t.Name = PostFileName; t.Content = text; var textToAdd = Mapper.Map <TextDto, Text>(t); instrumentToAdd.Texts.Add(textToAdd); if (httpRequest.Files.Count > 0) { try { for (int i = 0; i < httpRequest.Files.Count; i++) { var postedFile = httpRequest.Files[i]; string filePath = @"\ClinicInstruments\"; var fileInfo = FileUtil.SaveFile(postedFile, filePath, PostFileName); if (fileInfo[0] == "Picture") { PictureDto p = new PictureDto(); p.Name = fileInfo[1]; p.Url = filePath + fileInfo[1]; var picToAdd = Mapper.Map <PictureDto, Picture>(p); instrumentToAdd.Pictures.Add(picToAdd); } else if (fileInfo[0] == "Video") { VideoDto v = new VideoDto(); v.Name = fileInfo[1]; v.Url = filePath + fileInfo[1]; var videoToAdd = Mapper.Map <VideoDto, Video>(v); instrumentToAdd.Videos.Add(videoToAdd); } } } catch { } } else { msg = "请上传图片和视频!"; } clinicToAdd.Instruments.Add(instrumentToAdd); try { _context.Entry(clinicToAdd).State = EntityState.Modified; _context.SaveChanges(); msg = "添加成功"; } catch (RetryLimitExceededException) { msg = "网络故障"; } } var str = "{ \"Message\" : \"" + msg + "\" , \"" + "Data\" : \"" + "null" + "\" }"; return(Ok(str)); }
public async Task <ApiResponse> Create(TextDto textDto) { var text = await _textStore.Create(textDto); return(new ApiResponse(Status200OK, "Created text", text)); }
public async Task <ApiResponse> Put([FromBody] TextDto text) => ModelState.IsValid ? await _textManager.Update(text) : new ApiResponse(Status400BadRequest, "Text Model is Invalid");