/// <summary> /// Edits the course. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> public BaseOperationResponse EditCourse(CourseDto request) { var response = new BaseOperationResponse(); try { var unitOfWork = SWKM.Setup.IoC.Resolve<UnitOfWork>(); COURSE course; if (request.ID == 0) { // Dodanie kursu course = AutoMapper.Mapper.Map<CourseDto, COURSE>(request); unitOfWork.Courses.Add(course); unitOfWork.Save(); foreach (var deparature in request.Deparatures) { unitOfWork.Departures.Add( new DEPARTURE() { ROUTEID = deparature.RouteId, COURSEID = course.ID, TIME = deparature.Time }); } } else { foreach (var deparature in request.Deparatures) { var entity = unitOfWork.Departures.FindBy(d => d.ID == deparature.DeparatureId).SingleOrDefault(); entity.TIME = deparature.Time; } } unitOfWork.Save(); response.Successful = true; } catch (Exception e) { SWKM.Setup.Logger.Instance.Log.Error("Error occurred!", e); response.Successful = false; response.ErrorMessage = "Wystapił nie oczekiwany błąd przy edytowaniu kursu."; } return response; }
private void saveBtn_Click(object sender, EventArgs e) { if ((this.exceptionCbx.SelectedValue == null || (int)this.exceptionCbx.SelectedValue == 0) && (this.dayTypeCbx.SelectedValue == null || (int)this.dayTypeCbx.SelectedValue == 0)) { MessageBox.Show(this, "Musisz wybrać typ dnia lub wyjątek!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if ((int)this.lineCbx.SelectedValue == 0) { MessageBox.Show(this, "Musisz wybrać linię!", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // zapisywanie BaseOperationResponse response = null; var request = new CourseDto(); request.ID = this.courseId; request.LINEID = (int)this.lineCbx.SelectedValue; request.SCHEDULEPERIODID = (int)this.schedulePeriodCbx.SelectedValue; request.DAYTYPEID = (int)this.dayTypeCbx.SelectedValue; request.EXCEPTIONID = (int)this.exceptionCbx.SelectedValue; request.Deparatures = this.selectedDeparatureList; response = this.courseLogic.EditCourse(request); if (response.Successful) { this.coursesForm.RefreshGrid(); this.Close(); } else { MessageBox.Show(this, response.ErrorMessage, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }