protected void btnSave_Click(object sender, EventArgs e) { try { var rosterEvent = (ControlMode == SPControlMode.New) ? _dataService.CreateRosterEvent(ListId, (int)EventType): Item; if (rosterEvent == null) { throw new Exception("Roster event is empty"); } foreach (var field in ListMetadataFields.Select(item => item.Item2)) { var uiControls = FieldControls.FirstOrDefault(item => item.Item2.ID == field.InternalName.ToString()); if (uiControls == null) { continue; } if (uiControls.Item3.ReadOnly) { if (Request.QueryString[field.InternalName] != null) { rosterEvent.RosterEventDictionary[field.InternalName] = Request.QueryString[field.InternalName]; } } else { rosterEvent.RosterEventDictionary[field.InternalName] = uiControls.Item2.Value; } if (uiControls.Item3.Required && string.IsNullOrWhiteSpace(uiControls.Item2.Value.ToSafeString())) { ErrorHolder.Controls.Add(new Label { Text = @"Please fill out all required fields", ForeColor = System.Drawing.Color.Red }); return; } } // set ContentType if (rosterEvent.RosterEventDictionary.ContainsKey(FieldNames.CONTENT_TYPE_ID)) { if (rosterEvent.RosterEventDictionary[FieldNames.CONTENT_TYPE_ID] == null) { rosterEvent.RosterEventDictionary[FieldNames.CONTENT_TYPE_ID] = ContentTypeId; } } else { rosterEvent.RosterEventDictionary.Add(FieldNames.CONTENT_TYPE_ID, ContentTypeId); } // set StartDate and EndDate for AllDayEvent if (rosterEvent.RosterEventDictionary.ContainsKey(FieldNames.ALL_DAY_EVENT) && rosterEvent.RosterEventDictionary.ContainsKey(FieldNames.START_DATE) && rosterEvent.RosterEventDictionary.ContainsKey(FieldNames.END_DATE)) { var allDayEventObj = rosterEvent.RosterEventDictionary[FieldNames.ALL_DAY_EVENT]; if (allDayEventObj != null && allDayEventObj.ToBoolean()) { var startDt = rosterEvent.RosterEventDictionary[FieldNames.START_DATE]; var endDt = rosterEvent.RosterEventDictionary[FieldNames.END_DATE]; if (startDt != null && endDt != null) { rosterEvent.RosterEventDictionary[FieldNames.START_DATE] = ((DateTime)startDt).Date; rosterEvent.RosterEventDictionary[FieldNames.END_DATE] = ((DateTime)endDt).Date.AddMinutes(1439); } } } // check by Master Roster - if it is a Template - NO new rosters var masterRosterId = (rosterEvent.RosterEventDictionary.ContainsKey(FieldNames.MASTER_ROSTER_ID)) ? rosterEvent.RosterEventDictionary[FieldNames.MASTER_ROSTER_ID] : null; if (ControlMode == SPControlMode.New && this.ListId == TableIDs.PLANNED_ROSTERS && masterRosterId != null && _dataService.IsTemplate(masterRosterId.ToInt())) { throw new Exception("It is not possible to modify Roster Template!"); // do not allow ADD to Template } _dataService.SaveRosterEvent(rosterEvent, ListId); Utils.GoBackOnSuccess(this.Page, this.Context); } catch (Exception ex) { ErrorHolder.Controls.Add(new Label { Text = ex.ToReadbleSrting("Saving Error"), ForeColor = System.Drawing.Color.Red }); } }