/// <summary> /// Called when the user clicks okay. Performs validation and saves the data either into a new /// task or into task we are editing. /// </summary> protected void okBtn_Click(object sender, System.EventArgs e) { try { Task task = GetTask(); bool isNewTask = (task == null); if (isNewTask) task = new Task(); EditTaskController controller = new EditTaskController(); controller.Save(GetTaskData(), task); if (isNewTask) this.model.AddTask(task); Response.Redirect(ViewState["referrer"].ToString()); } catch (ValidateException ex) { validationLabel.Text = ex.Message; validationLabel.Visible = true; } }
/// <summary> /// Called when the page is loaded. When the page is loaded first time fills the controls with either /// defaults for new task or with information from the existing task. /// </summary> protected void Page_Load(object sender, System.EventArgs e) { this.model = this.Session["model"] as TasksModel; validationLabel.Visible = false; if (!this.IsPostBack) { //This is executed first time the page is loaded. ViewState["referrer"] = Request.UrlReferrer; //Fill combo boxes with standard choices. WebUtil.SetDataSource(monthlyDayCombo, EditTaskController.CreateDayList()); WebUtil.SetDataSource(monthlyDayOfWeekCombo, EditTaskController.CreateDayOfWeekList()); WebUtil.SetDataSource(monthlyNthOccurrenceCombo, EditTaskController.CreateNthOccurrenceList()); WebUtil.SetDataSource(monthlyDayOccurrenceCombo, EditTaskController.CreateWeekDayOccurrenceList()); WebUtil.SetDataSource(monthlyWeekDayTypeCombo, EditTaskController.CreateWeekDayTypeList()); WebUtil.SetDataSource(yearlyDayCombo, EditTaskController.CreateDayList()); WebUtil.SetDataSource(yearlyDayOfWeekCombo, EditTaskController.CreateDayOfWeekList()); WebUtil.SetDataSource(yearlyDayMonthCombo, EditTaskController.CreateMonthList()); WebUtil.SetDataSource(yearlyDayOfWeekMonthCombo, EditTaskController.CreateMonthList()); WebUtil.SetDataSource(yearlyNthOccurrenceCombo, EditTaskController.CreateNthOccurrenceList()); WebUtil.SetDataSource(yearlyDayOccurrenceCombo, EditTaskController.CreateWeekDayOccurrenceList()); WebUtil.SetDataSource(yearlyWeekDayTypeCombo, EditTaskController.CreateWeekDayTypeList()); WebUtil.SetDataSource(yearlyWeekDayMonthCombo, EditTaskController.CreateMonthList()); //Save id of the task we are editing in the view state. It will be null for new task. ViewState["taskId"] = Request.QueryString["taskId"]; EditTaskController controller = new EditTaskController(); if (GetTask() == null) { //Creating a new task. formLabel.Text = "New Task"; SetTaskData(controller.NewTask()); } else { //Editing existing task. formLabel.Text = "Edit Task"; SetTaskData(controller.LoadTask(GetTask())); } } }
private void UpdateiCalendar() { try { Task dummyTask = new Task(); EditTaskController controller = new EditTaskController(); controller.Save(GetTaskData(), dummyTask); iCalendarText.Text = dummyTask.Pattern.ToiCalendar(); } catch (Exception ex) { this.iCalendarText.Text = ex.Message; } }