Clean up SettingsController to not check for Null's as empty strings will not be null when returned.

class variables for _settingsSaved, _settingsFailed to easily change all error messages when saving
pull/3113/head
markus101 14 years ago
parent b2524cf697
commit ff44d05a72

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Repository.Quality
[Required (ErrorMessage = "A Name is Required")] [Required (ErrorMessage = "A Name is Required")]
[DisplayName("Name")] [DisplayName("Name")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string Name { get; set; } public string Name { get; set; }
public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles
@ -22,6 +23,7 @@ namespace NzbDrone.Core.Repository.Quality
[SubSonicIgnore] [SubSonicIgnore]
[DisplayName("Allowed Qualities String")] [DisplayName("Allowed Qualities String")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string AllowedString { get; set; } public string AllowedString { get; set; }
[DisplayName("Cutoff")] [DisplayName("Cutoff")]

@ -19,6 +19,8 @@ namespace NzbDrone.Web.Controllers
private IIndexerProvider _indexerProvider; private IIndexerProvider _indexerProvider;
private IQualityProvider _qualityProvider; private IQualityProvider _qualityProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private string _settingsSaved = "Settings Saved.";
private string _settingsFailed = "Error Saving Settings, please fix any errors";
public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider, IQualityProvider qualityProvider) public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider, IQualityProvider qualityProvider)
{ {
@ -146,60 +148,22 @@ namespace NzbDrone.Web.Controllers
return new QualityModel {DefaultProfileId = defaultQualityProfileId, SelectList = selectList}; return new QualityModel {DefaultProfileId = defaultQualityProfileId, SelectList = selectList};
} }
[HttpPost]
public ActionResult Index(SettingsModel data)
{
try
{
_configProvider.SeriesRoot = data.TvFolder;
}
catch (Exception)
{
Logger.Error("Error saving settings.");
if (Request.IsAjaxRequest())
return Content("Error saving settings.");
return Content("Error saving settings.");
}
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
return Content("Settings Saved.");
}
[HttpPost] [HttpPost]
public ActionResult SaveGeneral(SettingsModel data) public ActionResult SaveGeneral(SettingsModel data)
{ {
try if (ModelState.IsValid)
{ {
if (data.TvFolder != null)
_configProvider.SeriesRoot = data.TvFolder; _configProvider.SeriesRoot = data.TvFolder;
return Content(_settingsSaved);
//if (data.Quality != null)
// _configProvider.SetValue("Quality", data.Quality);
} }
catch (Exception e)
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors"); return Content(_settingsFailed);
}
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
return Content("Settings Saved.");
} }
[HttpPost] [HttpPost]
public ActionResult SaveIndexers(IndexerSettingsModel data) public ActionResult SaveIndexers(IndexerSettingsModel data)
{ {
try if (ModelState.IsValid)
{ {
//Todo: Only allow indexers to be enabled if user information has been provided //Todo: Only allow indexers to be enabled if user information has been provided
foreach (var indexer in data.Indexers) foreach (var indexer in data.Indexers)
@ -208,38 +172,17 @@ namespace NzbDrone.Web.Controllers
_indexerProvider.Update(indexer); _indexerProvider.Update(indexer);
} }
if (data.NzbMatrixUsername != null)
_configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername); _configProvider.SetValue("NzbMatrixUsername", data.NzbMatrixUsername);
if (data.NzbMatrixApiKey != null)
_configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey); _configProvider.SetValue("NzbMatrixApiKey", data.NzbMatrixApiKey);
if (data.NzbsOrgUId != null)
_configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId); _configProvider.SetValue("NzbsOrgUId", data.NzbsOrgUId);
if (data.NzbsOrgHash != null)
_configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash); _configProvider.SetValue("NzbsOrgHash", data.NzbsOrgHash);
if (data.NzbsrusUId != null)
_configProvider.SetValue("NzbsrusUId", data.NzbsrusUId); _configProvider.SetValue("NzbsrusUId", data.NzbsrusUId);
if (data.NzbsrusHash != null)
_configProvider.SetValue("NzbsrusHash", data.NzbsrusHash); _configProvider.SetValue("NzbsrusHash", data.NzbsrusHash);
} return Content(_settingsSaved);
catch (Exception e)
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors");
} }
if (Request.IsAjaxRequest()) return Content(_settingsFailed);
return Content("Settings Saved.");
return Content("Settings Saved.");
} }
[HttpPost] [HttpPost]
@ -247,67 +190,34 @@ namespace NzbDrone.Web.Controllers
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
try
{
if (data.SyncFrequency > 15)
_configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString()); _configProvider.SetValue("SyncFrequency", data.SyncFrequency.ToString());
_configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString()); _configProvider.SetValue("DownloadPropers", data.DownloadPropers.ToString());
if (data.Retention > 0)
_configProvider.SetValue("Retention", data.Retention.ToString()); _configProvider.SetValue("Retention", data.Retention.ToString());
if (data.SabHost != null)
_configProvider.SetValue("SabHost", data.SabHost); _configProvider.SetValue("SabHost", data.SabHost);
if (data.SabPort > 0)
_configProvider.SetValue("SabPort", data.SabPort.ToString()); _configProvider.SetValue("SabPort", data.SabPort.ToString());
if (data.SabApiKey != null)
_configProvider.SetValue("SabApiKey", data.SabApiKey); _configProvider.SetValue("SabApiKey", data.SabApiKey);
if (data.SabUsername != null)
_configProvider.SetValue("SabUsername", data.SabUsername); _configProvider.SetValue("SabUsername", data.SabUsername);
if (data.SabPassword != null)
_configProvider.SetValue("SabPassword", data.SabPassword); _configProvider.SetValue("SabPassword", data.SabPassword);
if (data.SabCategory != null)
_configProvider.SetValue("SabCategory", data.SabCategory); _configProvider.SetValue("SabCategory", data.SabCategory);
_configProvider.SetValue("SabPriority", data.SabPriority.ToString()); _configProvider.SetValue("SabPriority", data.SabPriority.ToString());
if (Request.IsAjaxRequest()) return Content(_settingsSaved);
return Content("Settings Saved.");
return Content("Settings Saved.");
} }
catch (Exception e) return Content(_settingsFailed);
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors");
}
}
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors");
} }
[HttpPost] [HttpPost]
public ActionResult SaveQuality(QualityModel data) public ActionResult SaveQuality(QualityModel data)
{
try
{ {
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
_configProvider.SetValue("DefaultQualityProfile", data.DefaultProfileId.ToString()); _configProvider.SetValue("DefaultQualityProfile", data.DefaultProfileId.ToString());
//Saves only the Default Quality, skips User Profiles since none exist
if (data.UserProfiles == null)
return Content(_settingsSaved);
foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile)) foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile))
{ {
if (!data.UserProfiles.Exists(p => p.ProfileId == dbProfile.ProfileId)) if (!data.UserProfiles.Exists(p => p.ProfileId == dbProfile.ProfileId))
@ -321,13 +231,13 @@ namespace NzbDrone.Web.Controllers
profile.Allowed = new List<QualityTypes>(); profile.Allowed = new List<QualityTypes>();
foreach (var quality in profile.AllowedString.Split(',')) foreach (var quality in profile.AllowedString.Split(','))
{ {
var qType = (QualityTypes) Enum.Parse(typeof (QualityTypes), quality); var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);
profile.Allowed.Add(qType); profile.Allowed.Add(qType);
} }
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit //If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
if (!profile.Allowed.Contains(profile.Cutoff)) if (!profile.Allowed.Contains(profile.Cutoff))
throw new InvalidOperationException("Invalid Cutoff Value"); return Content("Error Saving Settings, please fix any errors");
//profile.Cutoff = profile.Allowed.Last(); //profile.Cutoff = profile.Allowed.Last();
if (profile.ProfileId > 0) if (profile.ProfileId > 0)
@ -335,30 +245,12 @@ namespace NzbDrone.Web.Controllers
else else
_qualityProvider.Add(profile); _qualityProvider.Add(profile);
}
}
}
catch (Exception e) return Content(_settingsSaved);
{
Logger.ErrorException(e.Message, e);
if (Request.IsAjaxRequest())
return Content("Error Saving Settings, please fix any errors");
return Content("Error Saving Settings, please fix any errors");
} }
if (Request.IsAjaxRequest())
return Content("Settings Saved.");
return Content("Settings Saved.");
} }
[HttpPost] return Content(_settingsFailed);
public ActionResult SortedList(List<object> items)
{
return Content("Settings Saved.");
} }
} }
} }

@ -57,6 +57,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("SABnzbd API Key")] [DisplayName("SABnzbd API Key")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String SabApiKey public String SabApiKey
{ {
get; get;
@ -65,6 +66,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("SABnzbd Username")] [DisplayName("SABnzbd Username")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String SabUsername public String SabUsername
{ {
get; get;
@ -73,6 +75,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("SABnzbd Password")] [DisplayName("SABnzbd Password")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String SabPassword public String SabPassword
{ {
get; get;
@ -80,6 +83,7 @@ namespace NzbDrone.Web.Models
} }
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayFormat(ConvertEmptyStringToNull = false)]
[DisplayName("SABnzbd Category")] [DisplayName("SABnzbd Category")]
public String SabCategory public String SabCategory
{ {
@ -88,7 +92,6 @@ namespace NzbDrone.Web.Models
} }
[Required(ErrorMessage = "Please select a valid priority")] [Required(ErrorMessage = "Please select a valid priority")]
[DataType(DataType.Text)]
[DisplayName("SABnzbd Priority")] [DisplayName("SABnzbd Priority")]
public SabnzbdPriorityType SabPriority public SabnzbdPriorityType SabPriority
{ {

@ -12,6 +12,7 @@ namespace NzbDrone.Web.Models
{ {
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBMatrix Username")] [DisplayName("NZBMatrix Username")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbMatrixUsername public String NzbMatrixUsername
{ {
get; get;
@ -20,6 +21,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBMatrix API Key")] [DisplayName("NZBMatrix API Key")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbMatrixApiKey public String NzbMatrixApiKey
{ {
get; get;
@ -28,6 +30,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBs.Org UID")] [DisplayName("NZBs.Org UID")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbsOrgUId public String NzbsOrgUId
{ {
get; get;
@ -36,6 +39,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBs.Org Hash")] [DisplayName("NZBs.Org Hash")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbsOrgHash public String NzbsOrgHash
{ {
get; get;
@ -44,6 +48,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBsRus UID")] [DisplayName("NZBsRus UID")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbsrusUId public String NzbsrusUId
{ {
get; get;
@ -52,6 +57,7 @@ namespace NzbDrone.Web.Models
[DataType(DataType.Text)] [DataType(DataType.Text)]
[DisplayName("NZBsRus Hash")] [DisplayName("NZBsRus Hash")]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public String NzbsrusHash public String NzbsrusHash
{ {
get; get;

@ -11,8 +11,8 @@ namespace NzbDrone.Web.Models
public class SettingsModel public class SettingsModel
{ {
#region General Settings
[DataType(DataType.Text)] [DataType(DataType.Text)]
[Required(ErrorMessage = "Please enter a valid TV path")]
[DisplayName("TV Folder")] [DisplayName("TV Folder")]
public String TvFolder public String TvFolder
{ {
@ -27,159 +27,5 @@ namespace NzbDrone.Web.Models
get; get;
set; set;
} }
#endregion
//#region Indexer Settings
//[DataType(DataType.Text)]
//[DisplayName("NZBMatrix Username")]
//public String NzbMatrixUsername
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBMatrix API Key")]
//public String NzbMatrixApiKey
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBs.Org UID")]
//public String NzbsOrgUId
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBs.Org Hash")]
//public String NzbsOrgHash
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBsRus UID")]
//public String NzbsrusUId
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("NZBsRus Hash")]
//public String NzbsrusHash
//{
// get;
// set;
//}
//public List<Indexer> Indexers
//{
// get;
// set;
//}
//#endregion
//#region Download Settings
////Sync Frequency
////Download Propers?
////Retention
////SAB Host/IP
////SAB Port
////SAB APIKey
////SAB Username
////SAB Password
////SAB Category
////SAB Priority
//[DataType(DataType.Text)]
//[DisplayName("Sync Frequency")]
//public int SyncFrequency
//{
// get;
// set;
//}
//[DisplayName("Download Propers")]
//public bool DownloadPropers
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("Retention")]
//public int Retention
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Host")]
//public String SabHost
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Port")]
//public int SabPort
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd API Key")]
//public String SabApiKey
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Username")]
//public String SabUsername
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Password")]
//public String SabPassword
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Category")]
//public String SabCategory
//{
// get;
// set;
//}
//[DataType(DataType.Text)]
//[DisplayName("SABnzbd Priority")]
//public SabnzbdPriorityType SabPriority
//{
// get;
// set;
//}
//#endregion
} }
} }

@ -10,5 +10,7 @@
</asp:Content> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<% Html.RenderPartial(ViewData["viewName"].ToString()); %> <% Html.RenderPartial(ViewData["viewName"].ToString()); %>
</asp:Content> </asp:Content>

Loading…
Cancel
Save