예제 #1
0
 public NoteReferenceDTO GetItemById(int id)
 {
     if (id > 0)
     {
         try
         {
             NoteReference noteReference = _db.NoteReferences.GetItemById(id);
             if (noteReference != null)
             {
                 IMapper          mapper           = new MapperConfiguration(c => c.CreateMap <NoteReference, NoteReferenceDTO>()).CreateMapper();
                 NoteReferenceDTO noteReferenceDto = mapper.Map <NoteReference, NoteReferenceDTO>(noteReference);
                 noteReferenceDto.Reference = _db.Notes.GetItemById(noteReference.ReferenceId)?.Title;
                 return(noteReferenceDto);
             }
             else
             {
                 throw new NoteNotFoundException("Ссылка заметки не найдена");
             }
         }
         catch (NoteCustomException)
         {
             throw;
         }
         catch (Exception e)
         {
             throw new NoteCustomException(e.Message);
         }
     }
     else
     {
         throw new NoteArgumentException();
     }
 }
예제 #2
0
 public void Create(NoteReferenceDTO noteReference)
 {
     if (noteReference != null)
     {
         try
         {
             IMapper       mapper = new MapperConfiguration(c => c.CreateMap <NoteReferenceDTO, NoteReference>()).CreateMapper();
             NoteReference noteReferenceEntity = mapper.Map <NoteReferenceDTO, NoteReference>(noteReference);
             _db.NoteReferences.Save(noteReferenceEntity);
         }
         catch (NoteCustomException)
         {
             throw;
         }
         catch (Exception e)
         {
             throw new NoteCustomException(e.Message);
         }
     }
     else
     {
         throw new NoteArgumentException();
     }
 }