本文整理汇总了C#中Response.AddMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Response.AddMessage方法的具体用法?C# Response.AddMessage怎么用?C# Response.AddMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.AddMessage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateUserAsync
public static async Task<Response> CreateUserAsync(AddUserModel registerModel)
{
var response = new Response();
var context = new AdminDbContext();
ValidateUser(registerModel, response);
if (!response.Success)
{
return response;
}
if (context.Users.Any(u => u.Email.Equals(registerModel.Email)))
{
response.AddMessage(false, "This email is already registered", ResponseMessageType.Warning);
}
else
{
var user = new User();
user.Email = registerModel.Email;
user.Password = GenerateHashWithSalt(registerModel.Password, registerModel.Email);
user.PasswordSalt = Path.GetRandomFileName();
user.RegisterDate = registerModel.RegisterDate;
user.Active = registerModel.Active;
context.Users.Add(user);
await context.SaveChangesAsync();
}
return response;
}
示例2: AddRelationTypeAsync
public static async Task<Utils.Messages.Response> AddRelationTypeAsync(RelationTypeAddEditModel relationTypeModel)
{
var response = new Response();
var context = new AdminDbContext();
if (context.RelationTypes.Any(u => u.Code.Equals(relationTypeModel.Code)))
{
response.AddMessage(false, "This code is already registered", ResponseMessageType.Warning);
}
else
{
var relationType = new RelationType();
relationType.Code = relationTypeModel.Code;
relationType.Name = relationTypeModel.Name;
context.RelationTypes.Add(relationType);
await context.SaveChangesAsync();
}
return response;
}
示例3: Create
public static Response Create(RegisterModel registerModel)
{
var response = new Response();
var context = new AdminDbContext();
if (context.Users.Any(u => u.Email.Equals(registerModel.Email)))
{
response.AddMessage(false, "This email is already registered", ResponseMessageType.Warning);
}
else
{
var user = new User();
user.Email = registerModel.Email;
user.Password = GenerateHashWithSalt(registerModel.Password, registerModel.Email);
user.PasswordSalt = Path.GetRandomFileName();
context.Users.Add(user);
context.SaveChanges();
}
return response;
}
示例4: ValidateRelation
public static Response ValidateRelation(RelationAddEditModel relation, Response response = null)
{
response = response ?? new Response();
if (relation.TypeId == 0)
{
response.AddMessage(false, "Select a Relation Type", ResponseMessageType.Warning);
}
return response;
}
示例5: EditEntiTypeAsync
public static async Task<Utils.Messages.Response> EditEntiTypeAsync(EntityTypeAddEditModel entityTypeModel)
{
var response = new Response();
var context = new AdminDbContext();
if (context.EntityTypes.Any(u => u.Code.Equals(entityTypeModel.Code)&&!u.Id.Equals(entityTypeModel.Id)))
{
response.AddMessage(false, "This code is already registered on another entity", ResponseMessageType.Warning);
}
else
{
var entityType = context.EntityTypes.Find(entityTypeModel.Id);
entityType.Code = entityTypeModel.Code;
entityType.Name = entityTypeModel.Name;
await context.SaveChangesAsync();
}
return response;
}
示例6: ValidateEntityRelation
private static Response ValidateEntityRelation(AddEntityRelationModel addEntityRelationModel, Response response = null)
{
response = response ?? new Response();
if (addEntityRelationModel.Id == 0)
{
response.AddMessage(false, "Please select an entity", ResponseMessageType.Warning);
}
if (addEntityRelationModel.RelationTypeId == 0)
{
response.AddMessage(false, "Please select a relation type", ResponseMessageType.Warning);
}
if (addEntityRelationModel.OtherEntityId == 0)
{
response.AddMessage(false, "Please select the second entity", ResponseMessageType.Warning);
}
return response;
}
示例7: ValidateEntity
public static Response ValidateEntity(EntityAddEditModel entity, Response response = null)
{
response = response ?? new Response();
if (string.IsNullOrEmpty(entity.Name))
{
response.AddMessage(false, "The name should not be empty", ResponseMessageType.Warning);
}
if (entity.TypeId == 0)
{
response.AddMessage(false, "Select an Entity Type", ResponseMessageType.Warning);
}
return response;
}
示例8: GetUser
public static Response GetUser(string username, string password)
{
var response = new Response();
var context = new AdminDbContext();
var hashedPassword = GenerateHashWithSalt(password, username);
var user = context.Users.FirstOrDefault(u => u.Email.Equals(username) && u.Password.Equals(hashedPassword));
if (user != null)
{
response.Data = user;
}
else
{
response.AddMessage(false, "Username or password is invalid", ResponseMessageType.Warning);
}
return response;
}
示例9: ValidateUser
public static Response ValidateUser(AddUserModel registerModel, Response response = null)
{
response = response ?? new Response();
if (string.IsNullOrEmpty(registerModel.Email))
{
response.AddMessage(false, "Email is mandatory", ResponseMessageType.Warning);
}
if (registerModel.Id == 0)
{
if (string.IsNullOrEmpty(registerModel.Password))
{
response.AddMessage(false, "Password is mandatory", ResponseMessageType.Warning);
}
}
return response;
}