예제 #1
0
        public bool AddNoteToInspection(string inspectionUUID, string noteUUID, int noteType, string content, int orderNumber, string name, int userId, DateTime modifiedTime)
        {
            //find inspection id by uuid
            int inspectionId = context.Inspections.Where(i => i.UUID == inspectionUUID).Select(i => i.Id).FirstOrDefault();

            //create Note
            CSInspectionDatabaseModel.Note note = new CSInspectionDatabaseModel.Note();
            note.UUID = noteUUID;
            note.Type = noteType;
            note.Content = content;
            note.OrderNumber = orderNumber;
            note.CreatedBy = userId;
            note.ModifiedBy = userId;
            note.CreatedTime = modifiedTime;
            note.ModifiedTime = modifiedTime;
            note.UpdatedTime = DateTime.Now;
            note.Name = name;
            context.Notes.Add(note);
            context.SaveChanges();
            int noteId = context.Notes.Where(n => n.UUID == noteUUID).Select(n => n.Id).FirstOrDefault();

            //connect InspectionNote
            CSInspectionDatabaseModel.InspectionNote inspectionNote = new InspectionNote();
            inspectionNote.InspectionId = inspectionId;
            inspectionNote.NoteId = noteId;
            context.InspectionNotes.Add(inspectionNote);
            context.SaveChanges();

            bool isSuccess = context.InspectionNotes.Any(an => an.InspectionId == inspectionId && an.NoteId == noteId);
            return isSuccess;
        }
예제 #2
0
        public bool AddNoteToQuestion(string inspectionUUID, string noteUUID, int questionId, int noteType, string content, string name, int orderNumber, int userId, DateTime modifiedTime)
        {
            //find inspection id by uuid
            int inspectionId = context.Inspections.Where(i => i.UUID == inspectionUUID).Select(i => i.Id).FirstOrDefault();
            //finde answerId by InspectionId and questionId
            int answerId = context.Answers.Where(a => a.InspectionId == inspectionId && a.QuestionId == questionId).Select(a => a.Id).FirstOrDefault();

            //create Answer with inspectionId and questionId is not exist
            if (answerId == 0)
            {
                //create answer
                CSInspectionDatabaseModel.Answer answer = new CSInspectionDatabaseModel.Answer();
                answer.QuestionId = questionId;
                answer.AnsweredBy = userId;
                answer.InspectionId = inspectionId;
                answer.CreatedTime = modifiedTime;
                answer.ModifiedTime = modifiedTime;
                answer.UpdatedTime = DateTime.Now;
                context.Answers.Add(answer);
                context.SaveChanges();
                answerId = context.Answers.Where(a => a.InspectionId == inspectionId && a.QuestionId == questionId).Select(a => a.Id).FirstOrDefault();
            }

            //create Note
            CSInspectionDatabaseModel.Note note = new CSInspectionDatabaseModel.Note();
            note.UUID = noteUUID;
            note.Type = noteType;
            note.Content = content;
            note.OrderNumber = orderNumber;
            note.CreatedBy = userId;
            note.ModifiedBy = userId;
            note.CreatedTime = modifiedTime;
            note.ModifiedTime = modifiedTime;
            note.UpdatedTime = DateTime.Now;
            note.Name = name;
            context.Notes.Add(note);
            context.SaveChanges();
            int noteId = context.Notes.Where(n => n.UUID == noteUUID).Select(n => n.Id).FirstOrDefault();

            //connect AnswerNote
            CSInspectionDatabaseModel.AnswerNote answerNote = new AnswerNote();
            answerNote.AnswerId = answerId;
            answerNote.NoteId = noteId;
            context.AnswerNotes.Add(answerNote);
            context.SaveChanges();

            bool isSuccess = context.AnswerNotes.Any(an => an.AnswerId == answerId && an.NoteId == noteId);
            return isSuccess;
        }