Clean up OperationResponse method Part 1
This commit is contained in:
@@ -55,7 +55,7 @@ namespace CarCareTracker.Controllers
|
||||
}
|
||||
}
|
||||
}
|
||||
var successResponse = new OperationResponse { Success = true, Message = "Token Generated!" };
|
||||
var successResponse = OperationResponse.Succeed("Token Generated!");
|
||||
return Json(successResponse);
|
||||
} else
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace CarCareTracker.Controllers
|
||||
var originalFileName = Path.GetFileNameWithoutExtension(file.FileName);
|
||||
if (originalFileName == "en_US")
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "The translation file name en_US is reserved." });
|
||||
return Json(OperationResponse.Failed("The translation file name en_US is reserved."));
|
||||
}
|
||||
var fileName = UploadFile(file);
|
||||
//move file from temp to translation folder.
|
||||
@@ -43,7 +43,7 @@ namespace CarCareTracker.Controllers
|
||||
var result = _fileHelper.RenameFile(uploadedFilePath, originalFileName);
|
||||
return Json(new OperationResponse { Success = result, Message = string.Empty });
|
||||
}
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
||||
@@ -280,12 +280,12 @@ namespace CarCareTracker.Controllers
|
||||
var result = _loginLogic.UpdateUserDetails(userId, userAccount);
|
||||
return Json(result);
|
||||
}
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
@@ -496,13 +496,13 @@ namespace CarCareTracker.Controllers
|
||||
return Json(new OperationResponse() { Success = true, Message = $"{translationsDownloaded} Translations Downloaded" });
|
||||
} else
|
||||
{
|
||||
return Json(new OperationResponse() { Success = false, Message = "No Translations Downloaded" });
|
||||
return Json(OperationResponse.Failed("No Translations Downloaded"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Unable to retrieve translations: {ex.Message}");
|
||||
return Json(new OperationResponse() { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
}
|
||||
public ActionResult GetVehicleSelector(int vehicleId)
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace CarCareTracker.Controllers
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_configHelper.GetServerPostgresConnection()))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Postgres connection not set up" });
|
||||
return Json(OperationResponse.Failed("Postgres connection not set up"));
|
||||
}
|
||||
var tempFolder = $"temp/{Guid.NewGuid()}";
|
||||
var tempPath = $"{tempFolder}/cartracker.db";
|
||||
@@ -424,19 +424,19 @@ namespace CarCareTracker.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
}
|
||||
public IActionResult Import(string fileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_configHelper.GetServerPostgresConnection()))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Postgres connection not set up" });
|
||||
return Json(OperationResponse.Failed("Postgres connection not set up"));
|
||||
}
|
||||
var fullFileName = _fileHelper.GetFullFilePath(fileName);
|
||||
if (string.IsNullOrWhiteSpace(fullFileName))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -749,7 +749,7 @@ namespace CarCareTracker.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace CarCareTracker.Controllers
|
||||
var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplatesByVehicleId(planRecord.VehicleId).Where(x => x.Description == planRecord.Description).Any();
|
||||
if (planRecord.Id == default && existingRecord)
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "A template with that description already exists for this vehicle" });
|
||||
return Json(OperationResponse.Failed("A template with that description already exists for this vehicle"));
|
||||
}
|
||||
planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList();
|
||||
var result = _planRecordTemplateDataAccess.SavePlanRecordTemplateToVehicle(planRecord);
|
||||
@@ -72,7 +72,7 @@ namespace CarCareTracker.Controllers
|
||||
var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId);
|
||||
if (existingRecord.Id == default)
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Unable to find template" });
|
||||
return Json(OperationResponse.Failed("Unable to find template"));
|
||||
}
|
||||
if (existingRecord.Supplies.Any())
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace CarCareTracker.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Template has No Supplies" });
|
||||
return Json(OperationResponse.Failed("Template has No Supplies"));
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
@@ -90,7 +90,7 @@ namespace CarCareTracker.Controllers
|
||||
var existingRecord = _planRecordTemplateDataAccess.GetPlanRecordTemplateById(planRecordTemplateId);
|
||||
if (existingRecord.Id == default)
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Unable to find template" });
|
||||
return Json(OperationResponse.Failed("Unable to find template"));
|
||||
}
|
||||
if (existingRecord.Supplies.Any())
|
||||
{
|
||||
@@ -98,11 +98,11 @@ namespace CarCareTracker.Controllers
|
||||
var supplyAvailability = CheckSupplyRecordsAvailability(existingRecord.Supplies);
|
||||
if (supplyAvailability.Any(x => x.Missing))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Missing Supplies, Please Delete This Template and Recreate It." });
|
||||
return Json(OperationResponse.Failed("Missing Supplies, Please Delete This Template and Recreate It."));
|
||||
}
|
||||
else if (supplyAvailability.Any(x => x.Insufficient))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Insufficient Supplies" });
|
||||
return Json(OperationResponse.Failed("Insufficient Supplies"));
|
||||
}
|
||||
}
|
||||
if (existingRecord.ReminderRecordId != default)
|
||||
@@ -111,7 +111,7 @@ namespace CarCareTracker.Controllers
|
||||
var existingReminder = _reminderRecordDataAccess.GetReminderRecordById(existingRecord.ReminderRecordId);
|
||||
if (existingReminder is null || existingReminder.Id == default || !existingReminder.IsRecurring)
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Missing or Non-recurring Reminder, Please Delete This Template and Recreate It." });
|
||||
return Json(OperationResponse.Failed("Missing or Non-recurring Reminder, Please Delete This Template and Recreate It."));
|
||||
}
|
||||
}
|
||||
//populate createdDate
|
||||
|
||||
@@ -311,13 +311,13 @@ namespace CarCareTracker.Controllers
|
||||
var result = _fileHelper.MakeAttachmentsExport(attachmentData);
|
||||
if (string.IsNullOrWhiteSpace(result))
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
return Json(new OperationResponse { Success = true, Message = result });
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "No Attachments Found" });
|
||||
return Json(OperationResponse.Failed("No Attachments Found"));
|
||||
}
|
||||
}
|
||||
public IActionResult GetReportParameters()
|
||||
|
||||
@@ -188,7 +188,7 @@ namespace CarCareTracker.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new OperationResponse { Success = false, Message = "Both vehicles already have identical collaborators" });
|
||||
return Json(OperationResponse.Failed("Both vehicles already have identical collaborators"));
|
||||
}
|
||||
}
|
||||
return Json(new OperationResponse { Success = true, Message = "Collaborators Copied" });
|
||||
@@ -196,7 +196,7 @@ namespace CarCareTracker.Controllers
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return Json(new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage });
|
||||
return Json(OperationResponse.Failed());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ namespace CarCareTracker.Helper
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mailConfig.EmailServer))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "SMTP Server Not Setup" };
|
||||
return OperationResponse.Failed("SMTP Server Not Setup");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(emailAddress) || string.IsNullOrWhiteSpace(token)) {
|
||||
return new OperationResponse { Success = false, Message = "Email Address or Token is invalid" };
|
||||
return OperationResponse.Failed("Email Address or Token is invalid");
|
||||
}
|
||||
string emailSubject = "Your Registration Token for LubeLogger";
|
||||
string emailBody = $"A token has been generated on your behalf, please complete your registration for LubeLogger using the token: {token}";
|
||||
@@ -44,18 +44,18 @@ namespace CarCareTracker.Helper
|
||||
return new OperationResponse { Success = true, Message = "Email Sent!" };
|
||||
} else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
public OperationResponse NotifyUserForPasswordReset(string emailAddress, string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mailConfig.EmailServer))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "SMTP Server Not Setup" };
|
||||
return OperationResponse.Failed("SMTP Server Not Setup");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(emailAddress) || string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Email Address or Token is invalid" };
|
||||
return OperationResponse.Failed("Email Address or Token is invalid");
|
||||
}
|
||||
string emailSubject = "Your Password Reset Token for LubeLogger";
|
||||
string emailBody = $"A token has been generated on your behalf, please reset your password for LubeLogger using the token: {token}";
|
||||
@@ -66,18 +66,18 @@ namespace CarCareTracker.Helper
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
public OperationResponse NotifyUserForAccountUpdate(string emailAddress, string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mailConfig.EmailServer))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "SMTP Server Not Setup" };
|
||||
return OperationResponse.Failed("SMTP Server Not Setup");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(emailAddress) || string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Email Address or Token is invalid" };
|
||||
return OperationResponse.Failed("Email Address or Token is invalid");
|
||||
}
|
||||
string emailSubject = "Your User Account Update Token for LubeLogger";
|
||||
string emailBody = $"A token has been generated on your behalf, please update your account for LubeLogger using the token: {token}";
|
||||
@@ -88,22 +88,22 @@ namespace CarCareTracker.Helper
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
public OperationResponse NotifyUserForReminders(Vehicle vehicle, List<string> emailAddresses, List<ReminderRecordViewModel> reminders)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mailConfig.EmailServer))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "SMTP Server Not Setup" };
|
||||
return OperationResponse.Failed("SMTP Server Not Setup");
|
||||
}
|
||||
if (!emailAddresses.Any())
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "No recipients could be found" };
|
||||
return OperationResponse.Failed("No recipients could be found");
|
||||
}
|
||||
if (!reminders.Any())
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "No reminders could be found" };
|
||||
return OperationResponse.Failed("No reminders could be found");
|
||||
}
|
||||
//get email template, this file has to exist since it's a static file.
|
||||
var emailTemplatePath = _fileHelper.GetFullFilePath(StaticHelper.ReminderEmailTemplate);
|
||||
@@ -126,11 +126,11 @@ namespace CarCareTracker.Helper
|
||||
return new OperationResponse { Success = true, Message = "Email Sent!" };
|
||||
} else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
} catch (Exception ex)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = ex.Message };
|
||||
return OperationResponse.Failed(ex.Message);
|
||||
}
|
||||
}
|
||||
private bool SendEmail(List<string> emailTo, string emailSubject, string emailBody) {
|
||||
|
||||
@@ -9,16 +9,16 @@ namespace CarCareTracker.Helper
|
||||
/// </summary>
|
||||
public static class StaticHelper
|
||||
{
|
||||
public static string VersionNumber = "1.4.0";
|
||||
public static string DbName = "data/cartracker.db";
|
||||
public static string UserConfigPath = "config/userConfig.json";
|
||||
public static string AdditionalWidgetsPath = "data/widgets.html";
|
||||
public static string GenericErrorMessage = "An error occurred, please try again later";
|
||||
public static string ReminderEmailTemplate = "defaults/reminderemailtemplate.txt";
|
||||
public static string DefaultAllowedFileExtensions = ".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx";
|
||||
public static string SponsorsPath = "https://hargata.github.io/hargata/sponsors.json";
|
||||
public static string TranslationPath = "https://hargata.github.io/lubelog_translations";
|
||||
public static string TranslationDirectoryPath = $"{TranslationPath}/directory.json";
|
||||
public const string VersionNumber = "1.4.0";
|
||||
public const string DbName = "data/cartracker.db";
|
||||
public const string UserConfigPath = "config/userConfig.json";
|
||||
public const string AdditionalWidgetsPath = "data/widgets.html";
|
||||
public const string GenericErrorMessage = "An error occurred, please try again later";
|
||||
public const string ReminderEmailTemplate = "defaults/reminderemailtemplate.txt";
|
||||
public const string DefaultAllowedFileExtensions = ".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx";
|
||||
public const string SponsorsPath = "https://hargata.github.io/hargata/sponsors.json";
|
||||
public const string TranslationPath = "https://hargata.github.io/lubelog_translations";
|
||||
public const string TranslationDirectoryPath = $"{TranslationPath}/directory.json";
|
||||
public const string ReportNote = "Report generated by LubeLogger, a Free and Open Source Vehicle Maintenance Tracker - LubeLogger.com";
|
||||
public static string GetTitleCaseReminderUrgency(ReminderUrgency input)
|
||||
{
|
||||
|
||||
@@ -130,15 +130,15 @@ namespace CarCareTracker.Helper
|
||||
bool isDefaultLanguage = userLanguage == "en_US";
|
||||
if (isDefaultLanguage && !create)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "The translation file name en_US is reserved." };
|
||||
return OperationResponse.Failed("The translation file name en_US is reserved.");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(userLanguage))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "File name is not provided." };
|
||||
return OperationResponse.Failed("File name is not provided.");
|
||||
}
|
||||
if (!translations.Any())
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Translation has no data." };
|
||||
return OperationResponse.Failed("Translation has no data.");
|
||||
}
|
||||
var translationFilePath = isDefaultLanguage ? _fileHelper.GetFullFilePath($"/defaults/en_US.json") : _fileHelper.GetFullFilePath($"/translations/{userLanguage}.json", false);
|
||||
try
|
||||
@@ -164,7 +164,7 @@ namespace CarCareTracker.Helper
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex.Message);
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
public string ExportTranslation(Dictionary<string, string> translations)
|
||||
|
||||
@@ -71,13 +71,13 @@ namespace CarCareTracker.Logic
|
||||
var existingUser = _userData.GetUserRecordById(userId);
|
||||
if (existingUser.Id == default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Invalid user" };
|
||||
return OperationResponse.Failed("Invalid user");
|
||||
}
|
||||
//validate user token
|
||||
var existingToken = _tokenData.GetTokenRecordByBody(credentials.Token);
|
||||
if (existingToken.Id == default || existingToken.EmailAddress != existingUser.EmailAddress)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Invalid Token" };
|
||||
return OperationResponse.Failed("Invalid Token");
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(credentials.UserName) && existingUser.UserName != credentials.UserName)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace CarCareTracker.Logic
|
||||
var existingUserWithUserName = _userData.GetUserRecordByUserName(credentials.UserName);
|
||||
if (existingUserWithUserName.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Username already taken" };
|
||||
return OperationResponse.Failed("Username already taken");
|
||||
}
|
||||
existingUser.UserName = credentials.UserName;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace CarCareTracker.Logic
|
||||
var existingUserWithEmailAddress = _userData.GetUserRecordByEmailAddress(credentials.EmailAddress);
|
||||
if (existingUserWithEmailAddress.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "A user with that email already exists" };
|
||||
return OperationResponse.Failed("A user with that email already exists");
|
||||
}
|
||||
existingUser.EmailAddress = credentials.EmailAddress;
|
||||
}
|
||||
@@ -115,21 +115,21 @@ namespace CarCareTracker.Logic
|
||||
var existingToken = _tokenData.GetTokenRecordByBody(credentials.Token);
|
||||
if (existingToken.Id == default || existingToken.EmailAddress != credentials.EmailAddress)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Invalid Token" };
|
||||
return OperationResponse.Failed("Invalid Token");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(credentials.EmailAddress) || string.IsNullOrWhiteSpace(credentials.UserName))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Username cannot be blank" };
|
||||
return OperationResponse.Failed("Username cannot be blank");
|
||||
}
|
||||
var existingUser = _userData.GetUserRecordByUserName(credentials.UserName);
|
||||
if (existingUser.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Username already taken" };
|
||||
return OperationResponse.Failed("Username already taken");
|
||||
}
|
||||
var existingUserWithEmail = _userData.GetUserRecordByEmailAddress(credentials.EmailAddress);
|
||||
if (existingUserWithEmail.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "A user with that email already exists" };
|
||||
return OperationResponse.Failed("A user with that email already exists");
|
||||
}
|
||||
_tokenData.DeleteToken(existingToken.Id);
|
||||
var newUser = new UserData()
|
||||
@@ -145,7 +145,7 @@ namespace CarCareTracker.Logic
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Something went wrong, please try again later." };
|
||||
return OperationResponse.Failed("Something went wrong, please try again later.");
|
||||
}
|
||||
}
|
||||
//handles user registration
|
||||
@@ -155,22 +155,22 @@ namespace CarCareTracker.Logic
|
||||
var existingToken = _tokenData.GetTokenRecordByBody(credentials.Token);
|
||||
if (existingToken.Id == default || existingToken.EmailAddress != credentials.EmailAddress)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Invalid Token" };
|
||||
return OperationResponse.Failed("Invalid Token");
|
||||
}
|
||||
//token is valid, check if username and password is acceptable and that username is unique.
|
||||
if (string.IsNullOrWhiteSpace(credentials.EmailAddress) || string.IsNullOrWhiteSpace(credentials.UserName) || string.IsNullOrWhiteSpace(credentials.Password))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Neither username nor password can be blank" };
|
||||
return OperationResponse.Failed("Neither username nor password can be blank");
|
||||
}
|
||||
var existingUser = _userData.GetUserRecordByUserName(credentials.UserName);
|
||||
if (existingUser.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Username already taken" };
|
||||
return OperationResponse.Failed("Username already taken");
|
||||
}
|
||||
var existingUserWithEmail = _userData.GetUserRecordByEmailAddress(credentials.EmailAddress);
|
||||
if (existingUserWithEmail.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "A user with that email already exists" };
|
||||
return OperationResponse.Failed("A user with that email already exists");
|
||||
}
|
||||
//username is unique then we delete the token and create the user.
|
||||
_tokenData.DeleteToken(existingToken.Id);
|
||||
@@ -187,7 +187,7 @@ namespace CarCareTracker.Logic
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Something went wrong, please try again later." };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -212,17 +212,17 @@ namespace CarCareTracker.Logic
|
||||
var existingToken = _tokenData.GetTokenRecordByBody(credentials.Token);
|
||||
if (existingToken.Id == default || existingToken.EmailAddress != credentials.EmailAddress)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Invalid Token" };
|
||||
return OperationResponse.Failed("Invalid Token");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(credentials.Password))
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "New Password cannot be blank" };
|
||||
return OperationResponse.Failed("New Password cannot be blank");
|
||||
}
|
||||
//if token is valid.
|
||||
var existingUser = _userData.GetUserRecordByEmailAddress(credentials.EmailAddress);
|
||||
if (existingUser.Id == default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Unable to locate user" };
|
||||
return OperationResponse.Failed("Unable to locate user");
|
||||
}
|
||||
existingUser.Password = GetHash(credentials.Password);
|
||||
var result = _userData.SaveUserRecord(existingUser);
|
||||
@@ -233,7 +233,7 @@ namespace CarCareTracker.Logic
|
||||
return new OperationResponse { Success = true, Message = "Password resetted, you will be redirected to login page shortly." };
|
||||
} else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -310,7 +310,7 @@ namespace CarCareTracker.Logic
|
||||
var existingToken = _tokenData.GetTokenRecordByEmailAddress(emailAddress);
|
||||
if (existingToken.Id != default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "There is an existing token tied to this email address" };
|
||||
return OperationResponse.Failed("There is an existing token tied to this email address");
|
||||
}
|
||||
var token = new Token()
|
||||
{
|
||||
@@ -323,7 +323,7 @@ namespace CarCareTracker.Logic
|
||||
result = _mailHelper.NotifyUserForRegistration(emailAddress, token.Body).Success;
|
||||
if (!result)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Token Generated, but Email failed to send, please check your SMTP settings." };
|
||||
return OperationResponse.Failed("Token Generated, but Email failed to send, please check your SMTP settings.");
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
@@ -332,7 +332,7 @@ namespace CarCareTracker.Logic
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
public bool DeleteUserToken(int tokenId)
|
||||
@@ -351,7 +351,7 @@ namespace CarCareTracker.Logic
|
||||
var existingUser = _userData.GetUserRecordByUserName(credentials.UserName);
|
||||
if (existingUser.Id == default)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Unable to find user" };
|
||||
return OperationResponse.Failed("Unable to find user");
|
||||
}
|
||||
var newPassword = Guid.NewGuid().ToString().Substring(0, 8);
|
||||
existingUser.Password = GetHash(newPassword);
|
||||
@@ -362,7 +362,7 @@ namespace CarCareTracker.Logic
|
||||
}
|
||||
else
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "Something went wrong, please try again later." };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -51,16 +51,16 @@ namespace CarCareTracker.Logic
|
||||
var userAccess = _userAccess.GetUserAccessByVehicleAndUserId(existingUser.Id, vehicleId);
|
||||
if (userAccess != null)
|
||||
{
|
||||
return new OperationResponse { Success = false, Message = "User is already a collaborator" };
|
||||
return OperationResponse.Failed("User is already a collaborator");
|
||||
}
|
||||
var result = AddUserAccessToVehicle(existingUser.Id, vehicleId);
|
||||
if (result)
|
||||
{
|
||||
return new OperationResponse { Success = true, Message = "Collaborator Added" };
|
||||
return OperationResponse.Succeed("Collaborator Added");
|
||||
}
|
||||
return new OperationResponse { Success = false, Message = StaticHelper.GenericErrorMessage };
|
||||
return OperationResponse.Failed();
|
||||
}
|
||||
return new OperationResponse { Success = false, Message = $"Unable to find user {username} in the system" };
|
||||
return OperationResponse.Failed($"Unable to find user {username} in the system");
|
||||
}
|
||||
public bool DeleteCollaboratorFromVehicle(int userId, int vehicleId)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
namespace CarCareTracker.Models
|
||||
using CarCareTracker.Helper;
|
||||
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class OperationResponse
|
||||
public class OperationResponseBase
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
public class OperationResponse: OperationResponseBase
|
||||
{
|
||||
public static OperationResponse Succeed(string message)
|
||||
{
|
||||
return new OperationResponse { Success = true, Message = message };
|
||||
}
|
||||
public static OperationResponse Failed(string message = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
message = StaticHelper.GenericErrorMessage;
|
||||
}
|
||||
return new OperationResponse { Success = false, Message = message};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
function deleteCollaborator(userId, vehicleId) {
|
||||
$.post('/Vehicle/DeleteCollaboratorFromVehicle', {userId: userId, vehicleId: vehicleId}, function(data){
|
||||
if (data) {
|
||||
successToast('Collaborator Removed');
|
||||
refreshCollaborators();
|
||||
} else {
|
||||
errorToast(genericErrorMessage());
|
||||
@@ -68,6 +69,7 @@
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
$.post('/Vehicle/AddCollaboratorsToVehicle', { username: result.value.userName, vehicleId: vehicleId }, function (data) {
|
||||
if (data.success) {
|
||||
successToast(data.message);
|
||||
refreshCollaborators();
|
||||
} else {
|
||||
errorToast(data.message)
|
||||
|
||||
Reference in New Issue
Block a user