/// <summary> /// Функция открытия главы для пользователя /// </summary> public void OpenTheory(int theoryId, int userId) { var record = _context.UserTheoryDocumentMarks.FirstOrDefault(el => el.UserId == userId && el.DocumentId == null && el.TheoryPartId.Equals(theoryId)); if (record == null) { var newRecord = new UserTheoryDocumentMark { UserId = userId, TheoryPartId = theoryId, IsCompleted = true }; _context.UserTheoryDocumentMarks.Add(newRecord); _context.SaveChanges(); var firstDoc = _context.TheoryDocuments.Where(td => td.TheoryPartId.Equals(theoryId)) .OrderBy(td => td.Seq).FirstOrDefault(); if (firstDoc != null) { _documentService.OpenDocument(firstDoc.Id, userId); } } }
/// <summary> /// Функция открытия документа для пользователя /// </summary> public void OpenDocument(int documentId, int userId) { var document = _context.TheoryDocuments.Find(documentId); if (document != null) { var newRecord = new UserTheoryDocumentMark { UserId = userId, TheoryPartId = document.TheoryPartId, DocumentId = document.Id, IsCompleted = false }; _context.UserTheoryDocumentMarks.Add(newRecord); _context.SaveChanges(); } }