public async Task <ActionResult <SubTopicResponseModel> > GetAllSubTopicByMainTopicID(long mainTopicID) { SubTopicResponseModel subTopicResponseModel = new SubTopicResponseModel(); subTopicResponseModel = await Task.Run(() => _lessonPlannerRepository.GetAllSubTopicByMainTopicID(mainTopicID)); return(Ok(subTopicResponseModel)); }
public SubTopicResponseModel GetAllSubTopicByMainTopicID(long mainTopicID) { SubTopicResponseModel subTopicResponseModel = new SubTopicResponseModel(); subTopicResponseModel.Data = new List <SubTopicDto>(); DataTable dataTable = new DataTable(); SqlConnection conn = new SqlConnection(DbHelper.DbConnectionString); try { SqlCommand command = new SqlCommand(@"dbo.uspGetAllSubTopicByMainTopicID", conn); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@MainTopicID", mainTopicID); conn.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(dataTable); subTopicResponseModel.Message = "Success"; subTopicResponseModel.StatusCode = 200; foreach (DataRow row in dataTable.Rows) { SubTopicDto subTopicModel = new SubTopicDto(); subTopicModel.SubTopicID = row["SubTopicID"] != DBNull.Value ? Convert.ToInt64(row["SubTopicID"].ToString()) : 0; subTopicModel.SubTopicNumber = row["SubTopicNumber"] != DBNull.Value ? Convert.ToString(row["SubTopicNumber"]) : string.Empty; subTopicModel.MainTopicNumber = row["MainTopicNumber"] != DBNull.Value ? Convert.ToString(row["MainTopicNumber"]) : string.Empty; subTopicModel.SubTopicTitle = row["SubTopicTitle"] != DBNull.Value ? Convert.ToString(row["SubTopicTitle"]) : string.Empty; subTopicModel.Introduction = row["Introduction"] != DBNull.Value ? Convert.ToString(row["Introduction"]) : string.Empty; subTopicModel.Objectives = row["Objectives"] != DBNull.Value ? Convert.ToString(row["Objectives"]) : string.Empty; subTopicModel.Material = row["Material"] != DBNull.Value ? Convert.ToString(row["Material"]) : string.Empty; subTopicModel.MainTopicID = row["MainTopicID"] != DBNull.Value ? Convert.ToInt64(row["MainTopicID"].ToString()) : 0; subTopicResponseModel.Data.Add(subTopicModel); } } catch (Exception ex) { subTopicResponseModel.StatusCode = 500; subTopicResponseModel.Message = ex.Message; subTopicResponseModel.Data = null; } finally { dataTable.Clear(); dataTable = null; conn.Close(); } return(subTopicResponseModel); }
public IEnumerable <object> GetTopicData(int id) { List <TopicResponseModel> allTopicList = new List <TopicResponseModel>(); var allTopics = _context.Topic.Where(x => x.OrderItemId == id).ToList(); if (allTopics != null) { foreach (var topic in allTopics) { TopicResponseModel topicResponseModel = new TopicResponseModel(); topicResponseModel.Name = topic.Name; topicResponseModel.Description = topic.Description; topicResponseModel.ImageUrl = _classBookModelFactory.PrepareURL(topic.ImageUrl); var allSubjectTopics = _context.SubTopic.Where(x => x.TopicId == topic.Id).ToList(); if (allSubjectTopics != null) { topicResponseModel.SubTopicCount = allSubjectTopics.Count; List <SubTopicResponseModel> allSubTopci = new List <SubTopicResponseModel>(); foreach (var subTopic in allSubjectTopics) { SubTopicResponseModel subTopicResponseModel = new SubTopicResponseModel(); subTopicResponseModel.Name = subTopic.Name; subTopicResponseModel.Description = subTopic.Description; subTopicResponseModel.ImageUrl = _classBookModelFactory.PrepareURL(subTopic.ImageUrl); subTopicResponseModel.VideoLink = _classBookModelFactory.PrepareURL(subTopic.VideoLink); allSubTopci.Add(subTopicResponseModel); } topicResponseModel.subTopicResponseModel = allSubTopci; } allTopicList.Add(topicResponseModel); } } return(allTopicList); }