protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { //get event values News tempNews = new News() { Id = newsId, Heading = txtMNAHeading.Text, Dated = Helper.GetBritishDate(txtMNADated.Text), Location = txtMNALocation.Text, Summary = txtMNASummary.Text, Details = ftbMNADetails.Text }; var errorList = ValidateNews(tempNews); if (errorList.Count == 0) { //read from viewstate if (ViewState["selectedResources"] == null) ViewState.Add("selectedResources", new List<Resource>(20)); tempNews.Resources = SelectResources.GetSelectedResources(); NewsManager.SaveNews(tempNews); Helper.GoToMessagePage(string.Format("News {0} saved successfully.", tempNews.Heading)); } else { lblMsg.Text = Helper.FormatMessageToUL(errorList); } } else { lblMsg.Text = Helper.FormatMessageToUL(new List<string>() { Resources.Messages.PageValidationFailed }); } }
protected List<string> ValidateNews(News valTonews) { List<string> errorMsg = new List<string>(25); if (string.IsNullOrEmpty(valTonews.Details)) errorMsg.Add(Resources.Messages.NewsDetailsMandatory); //check event duplicate if ((valTonews.Id > 0 && NewsManager.GetAllNews().Exists(x => x.Id != valTonews.Id && x.Heading == valTonews.Heading)) || (!(valTonews.Id > 0) && NewsManager.GetAllNews().Exists(x => x.Heading == valTonews.Heading))) errorMsg.Add(Resources.Messages.EventNameDuplidate); return errorMsg; }
public static int SaveNews(News newsToSave) { SqlParameter parameter = null; SqlParameter[] parameters = new SqlParameter[7]; //add parameters parameter = new SqlParameter("@NewsId", System.Data.SqlDbType.Int); parameter.Value = newsToSave.Id; parameters[0] = parameter; parameter = new SqlParameter("@NewsHeading", System.Data.SqlDbType.VarChar, 250); parameter.Value = newsToSave.Heading; parameters[1] = parameter; parameter = new SqlParameter("@NewsSummary", System.Data.SqlDbType.VarChar, 500); parameter.Value = newsToSave.Summary; parameters[2] = parameter; parameter = new SqlParameter("@NewsDetails", System.Data.SqlDbType.VarChar); parameter.Value = newsToSave.Details; parameters[3] = parameter; parameter = new SqlParameter("@NewsLocation", System.Data.SqlDbType.VarChar, 150); parameter.Value = newsToSave.Location; parameters[4] = parameter; parameter = new SqlParameter("@NewsDated", System.Data.SqlDbType.DateTime); parameter.Value = newsToSave.Dated; parameters[5] = parameter; parameter = new SqlParameter("@NewsResources", System.Data.SqlDbType.NVarChar); parameter.Value = ConvertNewsResourcesToXML(newsToSave.Resources); parameters[6] = parameter; MSSQLHandler.CurrentConnectionType = GetConnectionType(); //add parameters var result = MSSQLHandler.ExecuteNonQuery("SaveNews", parameters); //update cache for events Helper.ClearCache(Resources.CacheKeys.MasterNews); return result; }