Exemplo n.º 1
0
        public async Task <ActionResultReponese <string> > InsertAsync(string idStudent, string idTeacherMain, TopicsMeta topicsMeta)
        {
            var topicId = Guid.NewGuid().ToString();
            var isName  = await _topicsRepository.CheckExisName(topicsMeta.NameTopics);

            if (isName)
            {
                return(new ActionResultReponese <string>(-2, "NameTopics da ton tai", "Topics"));
            }

            var isTeacher = await _teacherRepository.CheckExistsAsync(idTeacherMain);

            if (!isTeacher)
            {
                return(new ActionResultReponese <string>(-2, "TeacherMain khong ton tai", "Teacher"));
            }
            var infotecherMain = await _teacherRepository.GetInfoAsync(idTeacherMain);

            // check giang vien full de tai chua
            var isTopicsFullExit = await _teacherRepository.CheckCountTopicsAsync(idTeacherMain);

            if (!isTopicsFullExit)
            {
                return(new ActionResultReponese <string>(-2, "IdTeacher full de tai", "Teacher"));
            }
            var infotecher2 = await _teacherRepository.GetInfoAsync(topicsMeta.IdTeacher2);

            var isStudent = await _studentRepository.CheckExistsAsync(idStudent);

            if (!isStudent)
            {
                return(new ActionResultReponese <string>(-2, "Student khong ton tai", "Student"));
            }
            var infostuddent = await _studentRepository.GetInfoAsync(idStudent);

            var topic = new Topics
            {
                id              = topicId,
                IdTopics        = topicsMeta.IdTopics?.Trim(),
                NameTopics      = topicsMeta.NameTopics?.Trim(),
                IdStudent       = idStudent?.Trim(),
                NameStudent     = infostuddent.Name?.Trim(),
                IdTeacherMain   = idTeacherMain?.Trim(),
                NameTeacherMain = infotecherMain.NameTeacher?.Trim(),
                IdTeacher2      = topicsMeta.IdTeacher2?.Trim(),
                NameTeacher2    = infotecher2.NameTeacher?.Trim(),
                IsApproval      = false,
                IsActive        = true,
                IsDelete        = false,
                CreateDate      = DateTime.Now,
                LastUpdate      = null
            };

            var result = await _topicsRepository.InsertAsync(topic);

            if (result <= 0)
            {
                return(new ActionResultReponese <string>(result, "Insert that bai", "Topics"));
            }

            return(new ActionResultReponese <string>(result, "Insert thanh cong", "Topics"));
        }