本文整理汇总了C#中Payload.AssignValidationErrors方法的典型用法代码示例。如果您正苦于以下问题:C# Payload.AssignValidationErrors方法的具体用法?C# Payload.AssignValidationErrors怎么用?C# Payload.AssignValidationErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Payload
的用法示例。
在下文中一共展示了Payload.AssignValidationErrors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public Payload<Resource> Delete(Resource obj)
{
// create payload
var payload = new Payload<Resource>();
// todo: check security
// validate
var rules = new ValidationRules();
rules.ValidateHasId(obj);
// assign errors from validation (if applicable)
payload.AssignValidationErrors(rules.Errors);
// check if valid
if (rules.IsValid)
{
// db delete (inactive)
using (var queries = new ResourceQueries())
{
queries.Delete(ref obj);
}
payload.Data = obj;
}
// todo: next steps in workflow
// return payload
return payload;
}
示例2: Login
public Payload<WebUser> Login(string username, string email, string password)
{
// create payload
var payload = new Payload<WebUser>();
// todo: check security
// Validate
var rules = new ValidationRules();
rules.ValidateLoginEvent(username, email, password);
// assign errors from validation (if applicable)
payload.AssignValidationErrors(rules.Errors);
// check if valid
if (rules.IsValid)
{
// hash password
var securityUtility = new SecurityUtilities();
var hashedPassword = securityUtility.HashSomething(password);
// get user based on email/username and hashed password
WebUser user = null;
using (var queries = new WebUserQueries())
{
user = queries.GetByLogin(username, email);
}
// check if user is found (empty)
if (user != null)
{
// compare passwords to verify login
if (hashedPassword == user.HashedPassword)
{
// valid, so assign payload
payload.Data = user;
// log activity
AuditUtilities.Log(user, ActivityEventItem.Login,
string.Format(Resources.AuditEntries.Login, username));
}
else
{
// password mismatch error
payload.Errors.Add("00404", Resources.Errors.ERR00404);
// log activity
AuditUtilities.Log(null, ActivityEventItem.LoginFailed,
string.Format(Resources.AuditEntries.LoginFailed, username, Resources.Errors.ERR00404));
}
}
else
{
// throw error on not found user
payload.Errors.Add("00405", Resources.Errors.ERR00405);
// log activity
AuditUtilities.Log(null, ActivityEventItem.LoginFailed,
string.Format(Resources.AuditEntries.LoginFailed, username, Resources.Errors.ERR00405));
}
}
// todo: next steps in workflow
// return payload
return payload;
}
示例3: Save
public Payload<WebUser> Save(WebUser obj)
{
// create payload
var payload = new Payload<WebUser>();
// todo: check security
// Prep obj
bool isNewUser = (obj.Guid == null || obj.Guid == Guid.Empty);
business.SetDefaults(ref obj);
// hash password
var securityUtility = new SecurityUtilities();
obj.HashedPassword = securityUtility.HashSomething(obj.Password);
// validate
var rules = new ValidationRules();
rules.Validate(obj);
// assign errors from validation (if applicable)
payload.AssignValidationErrors(rules.Errors);
// check if valid
if (rules.IsValid)
{
// if existing user, check the properties that have changed prior to update
var changedProperties = new StringBuilder();
bool isChangedPassword = false;
if (!isNewUser)
{
var originalUser = Get(obj.Guid).Data;
CheckChangedProperties(originalUser, obj, ref changedProperties);
isChangedPassword = CheckChangedPassword(originalUser, obj);
}
// save to db
using (var queries = new WebUserQueries())
{
queries.Save(ref obj);
}
// assign primary data
payload.Data = obj;
// log activity
if (isNewUser)
{
// new user
AuditUtilities.Log(obj, ActivityEventItem.Enroll,
string.Format(Resources.AuditEntries.Enroll, obj.Username));
}
else
{
// updated user
AuditUtilities.Log(obj, ActivityEventItem.ProfileUpdated,
string.Format(Resources.AuditEntries.ProfileUpdated, obj.Username, changedProperties));
// update if password was changed
if (isChangedPassword)
{
AuditUtilities.Log(obj, ActivityEventItem.PasswordChanged,
string.Format(Resources.AuditEntries.PasswordChanged, obj.Username));
}
}
}
// todo: next steps in workflow
// return payload
return payload;
}
示例4: Search
public Payload<List<Resource>> Search(string q)
{
// create payload
var payload = new Payload<List<Resource>>();
// todo: check security
// validate
var rules = new ValidationRules();
rules.ValidateIsNotEmpty(q);
// assign errors from validation (if applicable)
payload.AssignValidationErrors(rules.Errors);
// check if valid
if (rules.IsValid)
{
// search db
using (var queries = new ResourceQueries())
{
payload.Data = queries.Search(q);
}
}
// return payload
return payload;
}
示例5: Save
public Payload<Resource> Save(Resource obj)
{
// create payload
var payload = new Payload<Resource>();
// todo: check security
// Prep obj
bool isNewAsset = (obj.Id <= 0);
business.SetDefaults(ref obj);
// Check if we need to create new subject
foreach (var association in obj.TopicAssociations)
{
// Get from db and see if it already exists
var subjectLogic = new TopicAppLogic();
if (association.Topic == null)
{
// check if exists
var subjectIsNew = (subjectLogic.Get(association.Tag).Data == null);
if (subjectIsNew)
{
// create new subject
association.Topic = new Topic()
{
Tag = association.Tag,
ContributorGuid = association.ContributorGuid,
Contributor = association.Contributor,
Created = DateTime.Now
};
}
}
}
// validate
var rules = new ValidationRules();
rules.Validate(obj);
// assign errors from validation (if applicable)
payload.AssignValidationErrors(rules.Errors);
// check if valid
if (rules.IsValid)
{
// if existing asset, check the properties that have changed prior to update
var changedProperties = new StringBuilder();
if (!isNewAsset)
{
var originalAsset = Get(obj.Id).Data;
CheckChangedProperties(originalAsset, obj, ref changedProperties);
}
// save to db
using (var queries = new ResourceQueries())
{
queries.Save(ref obj);
}
// assign primary data
payload.Data = obj;
// log activity
if (isNewAsset)
{
// new asset
AuditUtilities.Log(obj.Contributor, ActivityEventItem.ResourceCreated,
string.Format(Resources.AuditEntries.ResourceCreated, obj.Contributor.Username));
}
else
{
// updated asset
AuditUtilities.Log(obj.Contributor, ActivityEventItem.ResourceModified,
string.Format(Resources.AuditEntries.ResourceModified, obj.Contributor.Username, changedProperties));
}
}
// todo: next steps in workflow
// return payload
return payload;
}