public async Task SendContestEssayAsync(string title, string description, string content, string userId, IEnumerable <string> teachersIds) { var contestId = this.GetContestNowId(DateTime.Now); if (contestId == -1) { throw new KeyNotFoundException(); } Essay essay = new Essay() { Title = title, Description = description, Content = content, ContestId = contestId, UserId = userId, Graded = false, }; await this.essayRepository.AddAsync(essay); await this.essayRepository.SaveChangesAsync(); await this.AddEssayTeacher(teachersIds, essay.Id); }
public List <Essay> Get(int?id, int?last, string search) { using (var db = new BlogContext()) { if (!string.IsNullOrEmpty(search)) { List <Essay> filteredEssays = db.Essays.AsNoTracking() .Where(e => e.Title.Contains(search) || e.Subtitle.Contains(search)) .OrderByDescending(e => e.PublishDate).ToList(); return(filteredEssays); } if (last.HasValue) { List <Essay> PaginatedEssays = db.Essays.AsNoTracking() .Where(e => e.Id > last.Value) .OrderByDescending(e => e.PublishDate).Take(10).ToList(); return(PaginatedEssays); } if (id.HasValue) { Essay essay = db.Essays.AsNoTracking().Where(e => e.Id.Equals(id.Value)).FirstOrDefault(); return(new List <Essay> { essay }); } return(db.Essays.ToList()); } }
/// <summary> /// 更新随笔的标签 /// </summary> /// <param name="selectedTags"></param> /// <param name="essay"></param> private void UpdateEssayTags(int[] selectedTags, Essay essay) { if (selectedTags == null) { essay.EssayTagAssignments = new List <EssayTagAssignment>(); return; } essay.EssayTagAssignments = essay.EssayTagAssignments ?? new List <EssayTagAssignment>(); var selectedTagsHS = new HashSet <int>(selectedTags); var essayTagsHS = new HashSet <int>(essay.EssayTagAssignments.Select(s => s.EssayTagID)); foreach (var tag in _context.EssayTags) { if (selectedTagsHS.Contains(tag.EssayTagID)) { if (!essayTagsHS.Contains(tag.EssayTagID)) { essay.EssayTagAssignments.Add(new EssayTagAssignment { EssayID = essay.EssayID, EssayTagID = tag.EssayTagID }); } } else { if (essayTagsHS.Contains(tag.EssayTagID)) { var tagToRemove = essay.EssayTagAssignments.SingleOrDefault(s => s.EssayTagID == tag.EssayTagID); _context.Remove(tagToRemove); } } } }
public async Task <IActionResult> Edit(Essay essay, int[] selectedTags) { if (ModelState.IsValid) { try { essay.Summary = essay.Content.StripHTML(); essay.UpdateTime = DateTime.Now; _context.Entry(essay).State = EntityState.Modified; _context.Entry(essay).Property(x => x.EssayID).IsModified = false; _context.Entry(essay).Property(x => x.CreateTime).IsModified = false; UpdateEssayTags(selectedTags, essay); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EssayExists(essay.EssayID)) { return(NotFound()); } else { throw; } } return(new JsonResult(essay.EssayID)); } throw new ArgumentException(); }
public StatisticsWindow(Essay essay) { InitializeComponent(); this.essay = essay; this.initCharts(); this.initTextboxes(); }
public ActionResult Essay(Essay essay) { using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); string query = "INSERT INTO Exam_Essay(ApplicantID,Essay1,Essay2,Essay3,Essay4,Essay5,Essay6,Essay7,Essay8,Essay9,Essay10,Essay11,Essay12,Essay13)" + "VALUES(@ApplicantID,@Essay1,@Essay2,@Essay3,@Essay4,@Essay5,@Essay6,@Essay7,@Essay8,@Essay9,@Essay10,@Essay11,@Essay12,@Essay13)"; SqlCommand sqlCmds = new SqlCommand(query, sqlCon); sqlCmds.Parameters.AddWithValue("@ApplicantID", Session["MasterlistID"].ToString()); sqlCmds.Parameters.AddWithValue("@Essay1", essay.Essay1); sqlCmds.Parameters.AddWithValue("@Essay2", essay.Essay2); sqlCmds.Parameters.AddWithValue("@Essay3", essay.Essay3); sqlCmds.Parameters.AddWithValue("@Essay4", essay.Essay4); sqlCmds.Parameters.AddWithValue("@Essay5", essay.Essay5); sqlCmds.Parameters.AddWithValue("@Essay6", essay.Essay6); sqlCmds.Parameters.AddWithValue("@Essay7", essay.Essay7); sqlCmds.Parameters.AddWithValue("@Essay8", essay.Essay8); sqlCmds.Parameters.AddWithValue("@Essay9", essay.Essay9); sqlCmds.Parameters.AddWithValue("@Essay10", essay.Essay10); sqlCmds.Parameters.AddWithValue("@Essay11", essay.Essay11); sqlCmds.Parameters.AddWithValue("@Essay12", essay.Essay12); sqlCmds.Parameters.AddWithValue("@Essay13", essay.Essay13); sqlCmds.ExecuteNonQuery(); string querys = "Update Masterlist set Applicant_TookExam = 1 WHERE MasterlistID = @Masterlistid"; SqlCommand sqlCmdss = new SqlCommand(querys, sqlCon); sqlCmdss.Parameters.AddWithValue("@Masterlistid", Convert.ToInt32(Session["MasterlistID"].ToString())); sqlCmdss.ExecuteNonQuery(); Session["timer"] = null; } return(RedirectToAction("End")); }
public ActionResult eayadd(string title, string titcount, bool ko) { try { using (BlognEntities blog = new BlognEntities()) { if (title == "" || titcount == "") { return(Json(new { date = "请填写完整", type = 0 }, JsonRequestBehavior.AllowGet)); } int count = blog.Essay.Where(a => a.estitle == title).ToList().Count(); if (count > 0) { return(Json(new { date = "文章名已经存在", type = 0 }, JsonRequestBehavior.AllowGet)); } Essay es = new Essay(); es.estitle = title; es.esconter = titcount; es.esdate = DateTime.Now; es.eisno = ko; blog.Essay.Add(es); blog.SaveChanges(); return(Json(new { date = "已添加", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { date = "保存出错,原因是:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public ActionResult eayup(bool ko, string id) { try { using (BlognEntities blog = new BlognEntities()) { if (id == "" || id == null) { return(Json(new { date = "请输入编号", type = 0 }, JsonRequestBehavior.AllowGet)); } int idd = int.Parse(id); int count = blog.Essay.Where(a => a.esid == idd).ToList().Count(); if (count == 0) { return(Json(new { date = "没有此编号的文章哦", type = 0 }, JsonRequestBehavior.AllowGet)); } Essay es = blog.Essay.Where(a => a.esid == idd).FirstOrDefault(); es.eisno = ko; blog.SaveChanges(); return(Json(new { date = "已修改", type = 1, isno = es.eisno }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { date = "保存出错,原因是:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public async Task DeleteEssayRow(int essayId) { Essay essay = db.Essays.Where(e => e.Id == essayId).FirstOrDefault(); db.Essays.Remove(essay); await db.SaveChangesAsync(); }
public async Task <ActionResult> Edit(int id, EditView model) { var TempDatabase = TemDatabase; Essay obj = TempDatabase.Essays.Include(x => x.Author).First(x => x.Id == id); if (obj == null) { return(Json(new { Completed = false, err = new string[] { "Nie znaleziono rozprawki" } })); } obj.LibraryResource = model.LibraryResource; TempDatabase.Entry(obj).State = EntityState.Modified; try { int f = await TempDatabase.SaveChangesAsync(); if (f >= 0) { return(Json( new { Completed = true } )); } else { return(Json(new { Completed = false, err = new string[] { "Błąd zapisu danych" } })); } } catch (Exception ex) { return(Json(new { Completed = false, err = new string[] { ex.Message } })); } }
public IActionResult EditEssay(int essayId) { Essay essay = db.Essays.Where(e => e.Id == essayId).FirstOrDefault(); var essayTag = db.EssayToTags.Where(e => e.EssayId == essayId).ToList(); return(View(ReturnEssayViewModel(essay, essayTag))); }
public async Task SeedContestEssayAsync(Essay essay, IEnumerable <string> teachersIds) { await this.essayRepository.AddAsync(essay); await this.essayRepository.SaveChangesAsync(); await this.AddEssayTeacher(teachersIds, essay.Id); }
void before_each() { essay = new Essay(); essay.Title = "valid title"; essay.Author = "bob"; essay.Publisher = "WorldWide"; essay.Version = "1"; essay.IsNull = "NotNullForNowSoThatWeDontBreakOtherTests"; }
public CreateEssayViewModel ReturnEssayViewModel(Essay essay, List <EssayTag> essayTag) { var model = new CreateEssayViewModel { Content = essay.Content, Description = essay.Description, Name = essay.Name, Specialization = essay.Specialization, Id = essay.Id, Tags = ConvertTagsToString(essayTag) }; return(model); }
public async Task UpdateEssayInDb(CreateEssayViewModel model, string[] tags) { Essay essay = ReturnUpdatedEssay(model); db.Update(essay); await db.SaveChangesAsync(); await UpdateTagsInDb(model, tags, essay); }
public void UpdateOldRating(int rating, int essayId, ApplicationUser user, Essay essay, UserEssayRating userEssayRating) { db.UserEssayRatings.Update(userEssayRating); double total = essay.AverageRating * essay.VotersCount - userEssayRating.Rating + rating; essay.AverageRating = total / essay.VotersCount; userEssayRating.Rating = rating; db.UserEssayRatings.Update(userEssayRating); }
public void AddNewRating(int rating, int essayId, ApplicationUser user, Essay essay) { db.UserEssayRatings.Add(new UserEssayRating { EssayId = essayId, UserId = user.Id, Rating = rating }); double total = essay.AverageRating * essay.VotersCount + rating; essay.VotersCount++; essay.AverageRating = total / essay.VotersCount; }
public async Task CreateEssayInDb(CreateEssayViewModel model, string[] tags) { var user = await userManager.GetUserAsync(User); Essay essay = AddNewEssayToDb(model, user).Result; await AddNewTags(tags, essay); await userManager.UpdateAsync(user); }
public Essay ReturnUpdatedEssay(CreateEssayViewModel model) { Essay essay = db.Essays.Where(e => e.Id == model.Id).First(); essay.Name = model.Name; essay.Description = model.Description; essay.Specialization = model.Specialization; essay.Content = model.Content; return(essay); }
public void ProcessRequest(HttpContext context) { CategoryContext categoryContext = new CategoryContext(); String userName = context.Request.QueryString["uname"].ToString(); String url = context.Request.QueryString["url"].ToString(); String type = context.Request.QueryString["type"].ToString(); if (type.Equals("rss")) { String ctyname = context.Request.QueryString["ctyname"].ToString(); Category category = categoryContext.Categories.Where(c => c.Name.ToString().Equals(ctyname)).FirstOrDefault(); var reader = XmlReader.Create(url); var feed = SyndicationFeed.Load(reader); String title = feed.Title.Text.ToString(); Rss rss = new Rss { Name = title, UserName = userName, Url = url }; category.Rsses.Add(rss); categoryContext.SaveChanges(); } else if (type.Equals("essay")) { String fvtname = context.Request.QueryString["fvtname"].ToString(); Favourite favourite = categoryContext.Favourites.Where(f => (f.UserName.ToString().Equals(userName) && f.Name.ToString().Equals(fvtname))).FirstOrDefault(); List <String> tad = getWebTitleAndDescription(url); String title = tad[0]; String description = tad[1]; Essay essay = new Essay { Url = url, Title = title, Description = description }; favourite.Essays.Add(essay); categoryContext.SaveChanges(); } //context.Response.ContentType = "text/plain"; //context.Response.Write(""); }
/// <summary> /// Type=21 私聊消息。 /// </summary> /// <param name="subType">子类型,11/来自好友 1/来自在线状态 2/来自群 3/来自讨论组。</param> /// <param name="sendTime">发送时间(时间戳)。</param> /// <param name="fromQQ">来源QQ。</param> /// <param name="msg">消息内容。</param> /// <param name="font">字体。</param> public override void PrivateMessage(int subType, int sendTime, long fromQQ, string msg, int font) { string rtMsg = "暂无信息"; try { MongoDbHelper mh = new MongoDbHelper(); // 处理私聊消息。 //CQ.SendPrivateMessage(fromQQ, String.Format("[{0}]你发的私聊消息是TTTTTTT:{1}", CQ.ProxyType, msg)); string[] msgArry = msg.Split(' '); if (msgArry[0] == "存" && msgArry.Length == 2) { Essay ey = new Essay { IntDT = DateTime.Now.AddHours(8), Status = 1, Content = msgArry[1] }; if (mh.Insert <Essay>(ey)) { rtMsg = "保存成功"; } } else if (msgArry[0] == "随机") { List <Essay> ey = mh.FindAll <Essay>(); Random rd = new Random(); rtMsg = ey[rd.Next(ey.Count)].Content; } else if (msgArry[0] == "随音") { List <Essay> ey = mh.FindAll <Essay>(); Random rd = new Random(); rtMsg = ey[rd.Next(ey.Count)].Content; WebRequest wq = WebRequest.Create("http://tsn.baidu.com/text2audio?tex=" + rtMsg + "&lan=zh&cuid=sYPpfBIOi3qrS21Fei7y7fwMGipVfmpN&ctp=1&tok=25.7077e0ea242cb5c86d7555fba1c9a1ce.315360000.1835708354.282335-10449163"); WebResponse wp = wq.GetResponse(); Stream imgstream = wp.GetResponseStream(); StreamToFile(imgstream, @":\1111.mp."); } else { //WebRequest wq = WebRequest.Create("http://www.tuling123.com/openapi/api?key=24defe87976c4fb19141d1142dc3c913&info=" + msg); //WebResponse wp = wq.GetResponse(); //string json = new StreamReader(wp.GetResponseStream()).ReadToEnd(); //JObject jp = (JObject)JsonConvert.DeserializeObject(json);//result为上面的Json数据 //rtMsg = jp["text"].ToString(); } } catch (Exception ex) { rtMsg = "错误信息:" + ex.Message; } CQ.SendPrivateMessage(fromQQ, rtMsg); }
public bool RatingVerification(int rating, ApplicationUser user, Essay essay) { if ((rating < 1 || rating > 5) || (user == null) || (essay == null)) { return(false); } else { return(true); } }
public ActionResult Create_Essay(Essay model, AccountLogin user) { DBHelper tmpDBHelper = new DBHelper(); var title = model.Title; var content = model.Content; var userID = Session["UserId"].ToString(); tmpDBHelper.SqlExcute("insert into Essay(UserId,EssayTitle,EssayContent) values('" + userID + "','" + title + "','" + content + "')"); return(Redirect("../Home/Index")); }
public IActionResult Publisher(Essay model, BlogApp app) { int valid = app.Save(model); if (valid == 0) { return(RedirectToAction("Error")); } return(RedirectToAction("Home")); }
public void Create(string studentId, string title, string content) { var essay = new Essay() { AuthorId = studentId, Title = title, Content = content, CreatedOn = DateTime.UtcNow }; this.essays.Add(essay); this.essays.Save(); }
public async Task AddNewTags(string[] tags, Essay essay) { foreach (var temporary in tags) { TryTakeNewTag(temporary); if (db.EssayToTags.Where(e => e.TagId == temporary && e.EssayId == essay.Id).FirstOrDefault() == null) { db.EssayToTags.Add(new EssayTag { TagId = temporary, EssayId = essay.Id }); } await db.SaveChangesAsync(); } }
public async Task <Essay> SeedEssayAsync(ApplicationDbContext context, string userId, int contestId) { Essay essay = new Essay() { ContestId = contestId, UserId = userId, Graded = true, }; context.Essays.Add(essay); await context.SaveChangesAsync(); return(essay); }
public async Task <IActionResult> Essay(int essayId) { Essay essay = db.Essays.Where(e => e.Id == essayId).FirstOrDefault(); if (essay == null) { return(View("essaynotfound")); } var user = await userManager.GetUserAsync(User); if (user != null) { SetUserRatingInViewData(essayId, user.Id); } return(View(essay)); }
/// <summary> /// 文章点赞 /// </summary> public ActionResult textzanadd(string idd) { try { if (idd == null || idd == "") { return(Json(new { data = "编号不能为空", type = 0 }, JsonRequestBehavior.AllowGet)); } if (Session["name"] == null || Session["name"].ToString() == "") { return(Json(new { data = "请先登录", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blog = new BlognEntities()) { int id = int.Parse(idd); var name = Session["name"].ToString(); var user = blog.Usersd.Where(a => a.usname == name).FirstOrDefault(); int uid = user.usid; //判断该用户是否点过赞 int i = blog.Eslike.Where(a => a.usid == uid && a.esid == id).ToList().Count(); if (i > 0) { return(Json(new { data = "您已经点过赞了", type = 0 }, JsonRequestBehavior.AllowGet)); } //文章 Essay text = blog.Essay.Where(a => a.esid == id).FirstOrDefault(); if (text == null) { return(Json(new { data = "文章不存在", type = 0 }, JsonRequestBehavior.AllowGet)); } //点赞 var eslike = new Eslike(); eslike.usid = user.usid; eslike.esid = text.esid; eslike.eldate = DateTime.Now; blog.Eslike.Add(eslike); text.esliang = text.esliang + 1; blog.SaveChanges(); return(Json(new { data = "谢谢客官", type = 1, liang = text.esliang }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { data = "点赞失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public void Update(Essay essay) { var orgEssay = this.essays .All() .Where(e => e.AuthorId == essay.AuthorId) .FirstOrDefault(); if (orgEssay == null) { this.Create(essay.AuthorId, essay.Title, essay.Content); return; } orgEssay.Title = essay.Title; orgEssay.Content = essay.Content; this.essays.Save(); }
public async Task <Essay> SeedEssayAsync(ApplicationDbContext context) { var user = await this.SeedUserAsync(context, TestEmail); var contest = await this.SeedFutureContestAsync(context); Essay essay = new Essay() { ContestId = contest.Id, UserId = user.Id, }; context.Essays.Add(essay); await context.SaveChangesAsync(); return(essay); }
private void ValidateModel(Essay essay) { if (essay == null) { throw new ArgumentNullException(Messages.ParametersCanNotBeNull); } if (string.IsNullOrEmpty(essay.Title)) { throw new ArgumentNullException(Messages.TitleCanNotBeNull); } if (string.IsNullOrEmpty(essay.Title)) { throw new ArgumentNullException(Messages.TitleCanNotBeNull); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string ip = HttpContext.Current.Request.UserHostAddress; if (sc.IsFirstLogin(ip)) { cookieUse("islogin", "0", 30); } if (cookieRead("islogin") != "0") { personal_seting.Text = cookieRead("username"); logining.Visible = false; personal_seting.Visible = true; wel.Visible = true; registering.Visible = false; signouting.Visible = true; } } int id = 1; id = Convert.ToInt32(Request.QueryString["id"]); Essay essay = null; EssayBLL bll = new EssayBLL(); if(bll.GetEssayById(id) != null) { essay = new Essay(); essay.A_content = bll.GetEssayById(id).A_content; essay.A_title = bll.GetEssayById(id).A_title; essay.A_imagesource = bll.GetEssayById(id).A_imagesource; essay.A_addtime = bll.GetEssayById(id).A_addtime; essay.A_hits = bll.GetEssayById(id).A_hits; essay.A_resource = bll.GetEssayById(id).A_resource; essay.A_author = bll.GetEssayById(id).A_author; A_content = essay.A_content; A_title = essay.A_title; A_imageSource = essay.A_imagesource; A_AddTime = essay.A_addtime.ToString(); A_Hits = essay.A_hits.ToString(); A_Resource = essay.A_resource; A_Author = essay.A_author; } }
// Saves question to test protected void btnSaveQuestion_Click(object sender, EventArgs e) { // Multiple choice question checked and saved if(rblChooseQuestion.SelectedValue == "Multiple Choice") if(txtMCQuestion.Text != String.Empty) if (txtMC1.Text != String.Empty || txtMC2.Text != String.Empty || txtMC3.Text != String.Empty || txtMC4.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Multiple Choice"); if(rdbMC1.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "A"); } else if (rdbMC2.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "B"); } else if (rdbMC3.Checked == true) { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "C"); } else { MultipleChoice newMCQuestion = new MultipleChoice(questionCounter, txtMCQuestion.Text, "D"); } MultipleChoiceChoice MCOption1 = new MultipleChoiceChoice(questionCounter, 'A', txtMC1.Text); MultipleChoiceChoice MCOption2 = new MultipleChoiceChoice(questionCounter, 'A', txtMC2.Text); MultipleChoiceChoice MCOption3 = new MultipleChoiceChoice(questionCounter, 'A', txtMC3.Text); MultipleChoiceChoice MCOption4 = new MultipleChoiceChoice(questionCounter, 'A', txtMC4.Text); questionList.Add(newQuestion); } // True False Question checked and saved if(rblChooseQuestion.SelectedValue == "True False") if(txtTFQuestion.Text != String.Empty) { Question newQuestion = new Question(questionCounter,Int32.Parse(ddlPointValue.SelectedValue), "True/False"); TrueFalse newTFQuestion = new TrueFalse(questionCounter, txtTFQuestion.Text, rblTrueFalse.SelectedValue.ToString()); questionList.Add(newQuestion); } // Fill in the Blank question checked and saved if (rblChooseQuestion.SelectedValue == "Short Answer") if (txtFBAnswer.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Short Answer"); if (txtFBStatementBegin.Text != String.Empty && txtFBStatementEnd.Text != String.Empty) { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, txtFBStatementBegin.Text, txtFBAnswer.Text, txtFBStatementEnd.Text); } else if(txtFBStatementBegin.Text != String.Empty) { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, String.Empty, txtFBAnswer.Text, txtFBStatementEnd.Text); } else { ShortAnswer newSAQuestion = new ShortAnswer(questionCounter, txtFBStatementBegin.Text, txtFBAnswer.Text, String.Empty); } questionList.Add(newQuestion); } // Matching question checked and saved if(rblChooseQuestion.SelectedValue == "Matching") { if (txtSectionName.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Matching"); Matching newMatching = new Matching(questionCounter, txtSectionName.Text); if (txtMQuestion1.Text != String.Empty && txtMAnswer1.Text != String.Empty) { MatchingQuestions newChoice1 = new MatchingQuestions(4, txtMQuestion1.Text, txtMAnswer1.Text); } if (txtMQuestion2.Text != String.Empty && txtMAnswer2.Text != String.Empty) { MatchingQuestions newChoice2 = new MatchingQuestions(4, txtMQuestion2.Text, txtMAnswer2.Text); } if (txtMQuestion3.Text != String.Empty && txtMAnswer3.Text != String.Empty) { MatchingQuestions newChoice3 = new MatchingQuestions(4, txtMQuestion3.Text, txtMAnswer3.Text); } if (txtMQuestion4.Text != String.Empty && txtMAnswer4.Text != String.Empty) { MatchingQuestions newChoice4 = new MatchingQuestions(4, txtMQuestion4.Text, txtMAnswer4.Text); } questionList.Add(newQuestion); } } // Essay question checked and saved if (rblChooseQuestion.SelectedValue == "Essay") if (txtEQuestion.Text != String.Empty) { Question newQuestion = new Question(questionCounter, Int32.Parse(ddlPointValue.SelectedValue), "Essay"); Essay newEssayQuestion = new Essay(questionCounter, txtEQuestion.Text); questionList.Add(newQuestion); } // tentative way to have unique questionIds questionCounter++; }