protected void btnSave_Click(object sender, EventArgs e) { Feature feature = new Feature { ID = AKConvert.ToInt64(btnSave.CommandArgument), Title = txtName.Text.Trim(), Description = txtDescription.Text.Trim() }; if (ddlApplications.SelectedValue != "0") { feature.ApplicationID = AKConvert.ToInt64(ddlApplications.SelectedValue); } if (FeaturesManager.SaveFeature(feature)) { if (fuImage != null && fuImage.PostedFile != null && !string.IsNullOrEmpty(fuImage.FileName)) { string file = Constants.FeatureImagesFolderPhisicalPath + feature.ID + Path.GetExtension(fuImage.FileName); fuImage.SaveAs(file); FeaturesManager.UpdateFeatureImage(feature.ID, Path.GetFileName(file)); } CacheManager.RefreshFeatures(); RedirectBack(); } }
public static bool SaveFeature(Feature feature) { using (var db = CreateDataContext()) { var featureInDB = db.Features.FirstOrDefault(s => s.ID == feature.ID) ?? new Feature(); featureInDB.ApplicationID = feature.ApplicationID; featureInDB.Description = feature.Description; featureInDB.Title = feature.Title; if (featureInDB.ID == 0) { db.Features.Add(featureInDB); } try { db.SaveChanges(); feature.ID = featureInDB.ID; return true; } catch (Exception ex) { //todo: log return false; } } }