public ObjectResult SaveGeneAnnotation(int geneId, [FromBody] AnnotationDto annotationDto) { if (!IsModelValid(annotationDto)) { return(_invalidModelStateMessage); } if (annotationDto.AppUserId.Equals(0)) { annotationDto.AppUserId = annotationDto.AppUser.Id; } annotationDto.AppUser = null; var annotationEntity = _mapper.Map <Annotation>(annotationDto); _context.Annotation.Add(annotationEntity); _context.SaveChanges(); var annotationGeneEntity = new AnnotationGene { GeneId = geneId, AnnotationId = annotationEntity.Id }; _context.AnnotationGene.Add(annotationGeneEntity); _context.SaveChanges(); annotationEntity = _context.Annotation .Include(annotation => annotation.AppUser) .Single(annotation => annotation.Id == annotationEntity.Id); return(Ok(_mapper.Map <AnnotationDto>(annotationEntity))); }
public ObjectResult SaveLiteratureAnnotation(int literatureId, [FromBody] AnnotationDto annotationDto) { if (!IsModelValid(annotationDto)) { return(BadRequest(_invalidModelStateMessage)); } var annotationEntity = _mapper.Map <Annotation>(annotationDto); _context.Annotation.Add(annotationEntity); _context.SaveChanges(); var annotationLiterature = new AnnotationLiterature { AnnotationId = annotationEntity.Id, LiteratureId = literatureId }; _context.AnnotationLiterature.Add(annotationLiterature); _context.SaveChanges(); annotationEntity = _context.Annotation .Include(a => a.AppUser) .Single(a => a.Id == annotationEntity.Id); return(Ok(_mapper.Map <AnnotationDto>(annotationEntity))); }
private bool IsModelValid(AnnotationDto annotationDto) { if (!ModelState.IsValid) { _invalidModelStateMessage = BadRequest(ModelState); return(false); } if (annotationDto.AppUserId.Equals(0)) { if (annotationDto.AppUser == null || annotationDto.AppUser.Id.Equals(0)) { _invalidModelStateMessage = BadRequest("AppUserId required"); return(false); } annotationDto.AppUserId = annotationDto.AppUser.Id; } if (annotationDto.Id > 0) { _invalidModelStateMessage = BadRequest("Only NEW annotation are valid"); return(false); } return(true); }
public ObjectResult AddAnnotationGeneVariantLiterature( int geneVariantLiteratureId, [FromBody] AnnotationDto annotationDto ) { try { var geneVariantLiterature = _context.GeneVariantLiterature .Find(geneVariantLiteratureId); var annotationEntity = _mapper.Map <Annotation>(annotationDto); _context.Annotation.Add(annotationEntity); _context.SaveChanges(); var annotationGeneVariantLiterature = new AnnotationGeneVariantLiterature { GeneVariantLiteratureId = geneVariantLiterature.Id, AnnotationId = annotationEntity.Id }; _context.AnnotationGeneVariantLiterature.Add(annotationGeneVariantLiterature); _context.SaveChanges(); annotationEntity = _context.Annotation .Include(annotation => annotation.AppUser) .Single(annotation => annotation.Id == annotationEntity.Id); return(Ok(_mapper.Map <AnnotationDto>(annotationEntity))); } catch (InvalidOperationException e) { return(NotFound("could not find GeneVariantLiterature" + e)); } }