protected void btnSave_Click(object sender, EventArgs e)
{
switch (Mode)
{
case AdminControlMode.Edit:
// update existing testimonial
var testimonial = context.Testimonials.Where(t => t.Id == TestimonialID).FirstOrDefault();
if (testimonial == null) return; // default 404 response
// mark route handled/found
RouteHelper.SetUrlParametersResolved();
testimonial.Name = Name.Text;
testimonial.UrlName = Regex.Replace(Name.Text.ToLower(), UrlNameCharsToReplace, UrlNameReplaceString);
testimonial.Summary = Summary.Text;
testimonial.Text = Text.Value.ToString();
testimonial.Rating = Rating.Value;
testimonial.Published = Published.Checked;
break;
case AdminControlMode.Create:
// create and save new testimonial
var newTestimonial = new Testimonial();
newTestimonial.Name = Name.Text;
newTestimonial.UrlName = Regex.Replace(Name.Text.ToLower(), UrlNameCharsToReplace, UrlNameReplaceString);
newTestimonial.Summary = Summary.Text;
newTestimonial.Text = Text.Value.ToString();
newTestimonial.Rating = Rating.Value;
newTestimonial.Published = Published.Checked;
context.Add(newTestimonial);
break;
}
// save and return to main view
context.SaveChanges();
Response.Redirect(ResolveUrl(SiteMapBase.GetActualCurrentNode().ParentNode.Url));
}