public bool UpdateTempPromoteData(TempPromotionTable temp) { TempPromotionTable data; if (temp.Id == -1) { data = _db.TempPromotionTables.Add(temp); } else { data = _db.TempPromotionTables.First(x => x.Id == temp.Id); data.IsPassed = temp.IsPassed; data.Remarks = temp.Remarks; data.NextClassSectionId = temp.NextClassSectionId; data.NextClassId = temp.NextClassId; } try { _db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(false); } temp.Id = data.Id; return(true); }
private void buttonSubmit_Click(object sender, EventArgs e) { DialogResult result1 = MessageBox.Show("Are you sure, you want to " + (isPassed?"Promote":"Demote") + " this student?", "Important Question", MessageBoxButtons.OKCancel); if (result1 == DialogResult.Cancel) { return; } int nextclassSecId = -1; if (comboBoxNextClassSection.Items.Count > 0) { nextclassSecId = ((ClassSectionViewModel)comboBoxNextClassSection.SelectedItem).ClassSectionId; } TempPromotionTable temp = new TempPromotionTable { Id = tempPromoteId, StudentId = studentInfo.StudentId, IsPassed = isPassed, NextClassId = isPassed ? (nextClassId == -1?(int?)null:nextClassId) : studentInfo.ClassId, NextClassSectionId = nextclassSecId == -1?(int?)null:nextclassSecId, CurrentYearId = _settingService.GetCurrentYear(), AverageMarks = _settingService.CalculateMarksForPromotion(studentInfo.StudentId), Remarks = textBoxRemarks.Text }; if (_settingService.UpdateTempPromoteData(temp)) { tempPromoteId = temp.Id; MessageBox.Show("Data Updated Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Data Update Failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }