// GET: Practice/Edit/5 public ActionResult Edit(int?id) { PracticeModel practice = new PracticeModel(); InitializePageData(); try { if (!id.HasValue) { DisplayWarningMessage("Looks like, the ID is missing in your request"); return(RedirectToAction("List")); } if (!practiceService.Exists(id.Value)) { DisplayWarningMessage($"Sorry, We couldn't find the POD with ID: {id.Value}"); return(RedirectToAction("List")); } PracticeDto practiceDto = practiceService.GetPractice(id.Value); practice = Mapper.Map <PracticeDto, PracticeModel>(practiceDto); } catch (Exception exp) { DisplayReadErrorMessage(exp); } return(View(practice)); }
public ActionResult Create(PracticeModel practice) { try { InitializePageData(); if (ModelState.IsValid) { if (practiceService.Exists(practice.PracticeName)) { DisplayWarningMessage($"The POD Name '{practice.PracticeName}' is duplicate"); return(View(practice)); } PracticeDto practiceModel = Mapper.Map <PracticeModel, PracticeDto>(practice); practiceService.CreatePractice(practiceModel); DisplaySuccessMessage($"New POD '{practice.PracticeName}' has been stored successfully"); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayLoadErrorMessage(exp); } return(View(practice)); }
public ActionResult Edit(int id, PracticeModel practice) { try { InitializePageData(); if (ModelState.IsValid) { if (practiceService.Exists(practice.PracticeName, practice.PracticeID)) { DisplayWarningMessage($"POD Name '{practice.PracticeName}' is duplicate"); return(View(practice)); } PracticeDto practiceModel = Mapper.Map <PracticeModel, PracticeDto>(practice); practiceService.UpdatePractice(practiceModel); DisplaySuccessMessage($"POD '{practice.PracticeName}' details have been modified successfully"); return(RedirectToAction("List")); } } catch (Exception exp) { DisplayUpdateErrorMessage(exp); } return(View(practice)); }
public IActionResult Run(PracticeModel model) { var book = BooksService.Get(model.SelectedBookID); if (book == default) { return(ShowErrorViewForNotFoundBook(model.SelectedBookID)); } var langFrom = AccountService.GetPrefferedNativeLanguage(); var langTo = AccountService.GetPrefferedSecondaryLanguage(); var words = book.Words.Select(w => (From: w[langFrom], To: w[langTo])) // TODO: Words could be not translated, fail? .Select((t, i) => (t.From.ID, t.To.ID, t.From.Text, t.To.Text, t.To.AlternateSpelling, t.To.Pronunciation, Index: i)) .ToList(); // TODO: verify correct word range var runModel = new RunPracticeModel { Test = "Test", Language = (langFrom.Name, langTo.Name), Book = (book.ID, book.Name), WordRange = (model.WordRangeTop, model.WordRangeBottom), Words = words .Where(w => w.Index <= model.WordRangeTop && w.Index >= model.WordRangeBottom) .ToArray() }; runModel.PracticeWords = runModel.Words.Select(w => new PracticeWords(w)).ToArray(); return(View(runModel)); } }
public ActionResult UpdatePractice(PracticeModel model) { if (ModelState.IsValid) { //Find the current object in the database and store for check later Practice practice = practiceBLL.GetPractice().Find(m => m.PracticeID == model.practice.PracticeID); //perform update practiceBLL.UpdatePractice(model.practice); //Find the new updated practice in the database Practice practiceUpdate = practiceBLL.GetPractice().Find(m => m.PracticeID == model.practice.PracticeID); //if the two objects are not the same then the update was a success if (practice != practiceUpdate) { //display Message ViewBag.Message = "Update Successful"; } else { ViewBag.Message = "Update Failed"; } } else { ViewBag.Message = "Invalid Entry"; } //return view model.PracticeType = model.practice.PracticeType; return(View(model)); }
public ActionResult TwoLevelPractice() { PracticeModel practice = new PracticeModel(users); var user = Session["Users"] as Users; practice.GetUsers(user.TeamID); return(View(practice)); }
//Make Conversion to BLL layer common class practice public Practice PracticeMap(PracticeModel practiceModel) { Practice practice = new Practice(); practice.PracticeType = practiceModel.PracticeType; practice.StartTime = practiceModel.StartTime; practice.EndTime = practiceModel.EndTime; return(practice); }
public ActionResult UpdatePractice(int id) { //Make a new View Model PracticeModel practiceModel = new PracticeModel(users); //find the current practice object in database and store in object Practice practice = practiceBLL.GetPractice().Find(m => m.PracticeID == id); //set value to model property object practice practiceModel.practice = practice; //return view of the model to display object in database return(View(practiceModel)); }
public async Task <IHttpActionResult> CreatePractice(PracticeModel practice) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var datamodel = this.TheModelFactory.CreateModel(practice); await this.AppRepository.Practices.AddAsync(datamodel); practice = this.TheModelFactory.CreateViewModel(datamodel); return(CreatedAtRoute("GetPracticeById", new { id = practice.Id }, practice)); }
public HttpResponseMessage CheckBsnr(PracticeModel Parameter) { var transaction = new TransactionalInformation(); var exists = docDataService.CheckBsnr(Parameter.PracticeID, Parameter.BSNR, connectionString, SessionToken, out transaction); if (transaction.ReturnStatus) { if (exists) { return(Request.CreateResponse(HttpStatusCode.NotAcceptable)); } return(Request.CreateResponse(HttpStatusCode.OK)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
/// <summary> /// Legt eine Übung am Server an /// </summary> /// <param name="scheduleId"></param> /// <param name="exerciseId"></param> /// <param name="timestamp"></param> /// <param name="weight"></param> /// <param name="repetitions"></param> /// <param name="numberOfRepetitions"></param> /// <returns></returns> public async Task <int> recordPractice(int scheduleId, int exerciseId, string userId, DateTime timestamp = default(DateTime), double weight = 0, int repetitions = 0, int numberOfRepetitions = 0, string username = "", string password = "") { try { PracticeModel practice = new PracticeModel(); practice.ScheduleId = scheduleId; practice.ExerciseId = exerciseId; practice.UserId = userId; practice.Timestamp = timestamp; practice.Weight = weight; practice.Repetitions = repetitions; practice.NumberOfRepetitions = numberOfRepetitions; if (session == null) { session = await getSession(username, password); } PracticeModel result = await session.Users.CreatePracticeAsync(practice); if (result.Id != 0) { return(result.Id); } else { return(0); } } catch (ServerException ex) { throw; } catch (Exception exc) { Console.WriteLine("Fehler beim Eintragen eines Trainings: " + exc.StackTrace); } return(0); }
public ActionResult AddPractice(PracticeModel practice) { if (ModelState.IsValid) { var user = Session["Users"] as Users; //Map to common object PracticeMapper practiceMap = new PracticeMapper(); Practice newPractice = practiceMap.PracticeMap(practice); newPractice.TeamID = user.TeamID; practiceBLL.CreatePractice(newPractice); List <Practice> getPractice = practiceBLL.GetPractice(); if (getPractice.Exists(m => m.PracticeType == newPractice.PracticeType)) { ViewBag.Message = "Practice Added"; } else { ViewBag.Message = "Practice Failed"; } } return(View()); }
public ActionResult DeletePractice(PracticeModel model) { //Find the current object in the database and store for check later Practice practice = practiceBLL.GetPractice().Find(m => m.PracticeID == model.practice.PracticeID); //Perform the delete in the database practiceBLL.DeletePractice(practice); //store in a boolean the list to check if the object still exists bool check = practiceBLL.GetPractice().Exists(m => m.PracticeID == model.practice.PracticeID); //if object doesn't exists in database list of objects if (check == false) { //display that the delete was successful ViewBag.Message = "Delete Successful"; } else { ViewBag.Message = "Delete Failed"; } //return view make sure to show in practice attendance view that cascading delete was successful return(View(model)); }
public async Task <IHttpActionResult> UpdatePractice([FromUri] int id, [FromBody] PracticeModel practice) { if (id != practice.Id) { ModelState.AddModelError("id", "The given id have to be the same as in the model"); } else if (!IsValidRequest(practice.UserId)) { ModelState.AddModelError("id", "You can only update your own practices"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool exists = await this.AppRepository.Exercise.ExistsAsync(id); try { var orig = await this.AppRepository.Practices.FindAsync(id); orig = this.TheModelFactory.CreateModel(practice, orig); await this.AppRepository.Practices.UpdateAsync(orig); } catch (DbUpdateConcurrencyException) { if (!exists) { return(NotFound()); } throw; } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Updates one practice entry /// </summary> /// <param name="id">practice id</param> /// <param name="model">practice data</param> /// <returns></returns> public async Task UpdatePracticeAsync(int id, PracticeModel model) { await PutAsJsonAsync(model, "api/practice/" + id); }
public dynamic SubmitPractice(PracticeModel model) { return(Success(mapper.SubmitPractice(model, this.SafeGetStuId) ? "交卷成功" : "交卷失败")); }
public ActionResult TwoLevelPractice(PracticeModel practice) { if (ModelState.IsValid) { if (practice.PracticeType == "") { ViewBag.Message = "Cannot leave practice blank"; return(View(practice)); } if (practice.StartTime < DateTime.Now) { ViewBag.Message = "Start Time cannot be earlier than todays date"; return(View(practice)); } else if (practice.EndTime < DateTime.Now) { ViewBag.Message = "End Time Cannot be earlier than todays date"; return(View(practice)); } else if (practice.StartTime > practice.EndTime) { ViewBag.Message = "Start Time Cannot be later than End Time"; return(View(practice)); } else if (practice.StartTime == DateTime.MinValue || practice.EndTime == DateTime.MinValue) { ViewBag.Message = "Cannot be the beggining of time"; return(View(practice)); } var users = Session["Users"] as Users; Practice createPractice = new Practice(); PracticeAttended absent = new PracticeAttended(); createPractice.PracticeType = practice.PracticeType; createPractice.StartTime = practice.StartTime; createPractice.EndTime = practice.EndTime; absent.UserID = practice.UserID; absent.Attended = practice.Check; createPractice.TeamID = users.TeamID; practiceBLL.CreatePractice(createPractice); List <Practice> check = practiceBLL.GetPractice(); check.Reverse(); Practice checkinsert = check.Find(m => m.PracticeType == createPractice.PracticeType && m.StartTime == createPractice.StartTime && m.EndTime == createPractice.EndTime); absent.PracticeID = checkinsert.PracticeID; attendance.CreatePracticeAttendance(absent); bool insert = check.Exists(m => m.PracticeType == practice.PracticeType); bool checkInsert = attendance.getPracticeAttendaned(users.TeamID).Exists(m => m.PracticeID == check[0].PracticeID); if (insert && checkInsert) { ViewBag.Message = "Practice and Attendance Created"; } else if (insert && checkInsert == false) { ViewBag.Message = "Only Practice Added"; } else if (insert == false && checkInsert == false) { ViewBag.Message = "No Insert Made"; } else { } } else { ViewBag.Message = "Invalid Entry"; } return(View(practice)); }
/// <summary> /// 创建章节练习 /// </summary> /// <param name="model"></param> /// <returns></returns> public PracticeModel CreateChapterPractice(W_ChapterPractice model, int chapterId, string questionType, int questionCount, int questionSource) { PracticeModel rtn = new PracticeModel(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == model.StuId).ToList();//题目笔记列表 //判断是重新生成章节练习还是继续之前的章节练习 W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.Source == model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId && x.Status == 0); if (cp != null)//继续做题 { rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); if (result == null) { throw new ApiException("练习有误,请刷新重试"); } rtn.resultId = result.ID; List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = model.StuId }).ToList(); foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = model.AddTime; Orm.Update <W_DoExamResult>(result); } else//重新生成 { List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeQuestion", new { chapterId, questionType, questionCount, questionSource, stuId = model.StuId }).ToList(); if (list.Count == 0) { throw new ApiException("没有更多的试题"); } //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID == chapterId).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult result = new W_DoExamResult(); result.StuId = model.StuId; result.BusType = 1;//章节练习 result.BusID = practiceId; result.BeginTime = model.AddTime; result.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(result, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } return(rtn); }
/// <summary> /// 继续做题 做题记录页面进来,继续/重新做题 继续做题:继续原来未完成的做题记录 重新做题:开始新的做题记录,题目和原做题记录题目一致(刷新页面确保逻辑一致) /// </summary> /// <param name="ID"></param> /// <param name="stuId"></param> /// <returns></returns> public dynamic ContinueChapterPractice(int ID, string stuId) { PracticeModel rtn = new PracticeModel(); W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == ID); if (cp == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = stuId }).ToList(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList(); //题目笔记列表 if (result.Valid == 1) //重新做题 { W_ChapterPractice cp2 = Orm.Single <W_ChapterPractice>(x => x.Source == cp.Source && x.Status == 0); //重新做题页面刷新 if (cp2 == null) { string[] str = cp.Source.Split('_'); if (str.Length != 6) { throw new ApiException("练习记录数据有误"); } W_ChapterPractice model = new W_ChapterPractice(); model.QuestionStore_ID = int.Parse(str[0]); model.AddTime = DateTime.Now; model.StuId = stuId; //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID.ToString() == str[1]).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = cp.Source; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult res = new W_DoExamResult(); res.StuId = model.StuId; res.BusType = 1;//章节练习 res.BusID = practiceId; res.BeginTime = model.AddTime; res.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(res, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } else { W_DoExamResult result2 = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp2.ID); if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result2.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result2.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result2); } } else { if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result); } return(rtn); }
/// <summary> /// 交卷 /// </summary> /// <param name="model"></param> /// <param name="stuId"></param> /// <returns></returns> public bool SubmitPractice(PracticeModel model, string stuId) { W_DoExamResult result = Orm.Select <W_DoExamResult>(x => x.ID == model.resultId).FirstOrDefault(); if (result == null) { throw new ApiException("对象错误"); } else if (string.IsNullOrEmpty(stuId) || result.StuId != stuId) { throw new ApiException("登陆超时,请重新登陆"); } result.EndTime = DateTime.Now; result.Valid = 1;//交卷 SqlMapper.BeginTransaction(); try { //获取试卷题型对应的分数 List <W_ExamPaperDetail> detailList = null; if (result.BusType == 0)//试卷模式 { //更新试卷测试次数 W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == result.BusID); paper.DoCount += 1; Orm.Update <W_ExamPaper>(paper); //试卷题型对应得分 detailList = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == result.BusID).ToList(); } else//更改章节练习状态 { W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == result.BusID); cp.Status = 1; Orm.Update <W_ChapterPractice>(cp); } //保存做题记录明细 foreach (Question question in model.list) { decimal sorce = 0; if (result.BusType == 0)//试卷模式 { W_ExamPaperDetail temp = detailList.FirstOrDefault(x => x.QuestionType_ID == question.QuestionType_ID); sorce = temp != null ? temp.Sorce : 0; } Orm.Insert <W_DoExamResult_Detail>(new W_DoExamResult_Detail() { DoExamResult_ID = result.ID, Question_ID = question.ID, StuID = result.StuId, MyAnswer = question.MyAnswer, Judge = question.Judge, Sorce = sorce, UpdateTime = result.EndTime }); //更新题目信息 SqlMapper.Update("UpdateQuestion", new { ID = question.ID, Judge = question.Judge, EasyWrongAnswer = question.MyAnswer }); } //修改做题记录主表 Orm.Update <W_DoExamResult>(result); SqlMapper.CommitTransaction(); } catch { SqlMapper.RollBackTransaction(); return(false); } return(true); }
/// <summary> /// Creates an new Practice /// </summary> /// <param name="model">practice data</param> /// <returns></returns> public async Task <PracticeModel> CreatePracticeAsync(PracticeModel model) { return(await this.PostAsJsonReturnAsync <PracticeModel, PracticeModel>(model, "api/practice")); }