protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { //get event values History tempHistory = new History() { Id = historyId, Title = txtMHATitle.Text, Details = ftbMHADetails.Text, Type = txtMHAType.Text }; var errorList = ValidateHistory(tempHistory); if (errorList.Count == 0) { HistoryManager.SaveHistory(tempHistory); Helper.GoToMessagePage(string.Format("Event {0} saved successfully.", tempHistory.Title)); } else { lblMsg.Text = Helper.FormatMessageToUL(errorList); } } else { lblMsg.Text = Helper.FormatMessageToUL(new List<string>() { Resources.Messages.PageValidationFailed }); } }
public static int SaveHistory(History historyToSave) { SqlParameter parameter = null; SqlParameter[] parameters = new SqlParameter[4]; //add parameters parameter = new SqlParameter("@HistoryId", System.Data.SqlDbType.Int); parameter.Value = historyToSave.Id; parameters[0] = parameter; parameter = new SqlParameter("@HistoryTitle", System.Data.SqlDbType.VarChar, 250); parameter.Value = historyToSave.Title; parameters[1] = parameter; parameter = new SqlParameter("@HistoryType", System.Data.SqlDbType.VarChar, 150); parameter.Value = historyToSave.Type; parameters[2] = parameter; parameter = new SqlParameter("@HistoryDetails", System.Data.SqlDbType.VarChar); parameter.Value = historyToSave.Details; parameters[3] = parameter; MSSQLHandler.CurrentConnectionType = GetConnectionType(); //add parameters var result = MSSQLHandler.ExecuteNonQuery("SaveHistory", parameters); //update cache for events Helper.ClearCache(Resources.CacheKeys.MasterHistories); return result; }
protected List<string> ValidateHistory(History valToHistory) { List<string> errorMsg = new List<string>(25); if (string.IsNullOrEmpty(valToHistory.Details)) errorMsg.Add(Resources.Messages.HistoryDetailsMandatory); //check event duplicate if ((valToHistory.Id > 0 && HistoryManager.GetAllHistories().Exists(x => x.Id != valToHistory.Id && x.Title == valToHistory.Title)) || (!(valToHistory.Id > 0) && HistoryManager.GetAllHistories().Exists(x => x.Title == valToHistory.Title))) errorMsg.Add(Resources.Messages.HistoryNameDuplicate); return errorMsg; }