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; }
public static async Task<Utils.Messages.Response> EditRelationAsync(RelationAddEditModel relationModel) { var response = new Response(); var context = new AdminDbContext(); ValidateRelation(relationModel, response); if (!response.Success) { return response; } var relation = context.Relations.Find(relationModel.Id); relation.TypeId = relationModel.TypeId; await context.SaveChangesAsync(); return response; }
public static async Task<Utils.Messages.Response> DeleteRelationAsync(long id) { var response = new Response(); var context = new AdminDbContext(); var relation = context.Relations.Find(id); if (relation != null) { context.Relations.Remove(relation); await context.SaveChangesAsync(); } return response; }
public static async Task<Utils.Messages.Response> EditRelationTypeAsync(RelationTypeAddEditModel relationTypeModel) { var response = new Response(); var context = new AdminDbContext(); if (context.RelationTypes.Any(u => u.Code.Equals(relationTypeModel.Code) && !u.Id.Equals(relationTypeModel.Id))) { response.AddMessage(false, "This code is already registered on another entity", ResponseMessageType.Warning); } else { var relationType = context.RelationTypes.Find(relationTypeModel.Id); relationType.Code = relationTypeModel.Code; relationType.Name = relationTypeModel.Name; await context.SaveChangesAsync(); } return response; }
public static async Task<Utils.Messages.Response> AddEntiTypeAsync(EntityTypeAddEditModel entityTypeModel) { var response = new Response(); var context = new AdminDbContext(); if (context.EntityTypes.Any(u => u.Code.Equals(entityTypeModel.Code))) { response.AddMessage(false, "This code is already registered", ResponseMessageType.Warning); } else { var entityType = new EntityType(); entityType.Code = entityTypeModel.Code; entityType.Name = entityTypeModel.Name; context.EntityTypes.Add(entityType); await context.SaveChangesAsync(); } return response; }
public static async Task<Utils.Messages.Response> DeleteEntiTypeAsync(long id) { var response = new Response(); var context = new AdminDbContext(); var entityType = context.EntityTypes.Find(id); if(entityType!=null) { context.EntityTypes.Remove(entityType); await context.SaveChangesAsync(); } return response; }
public static async Task<Utils.Messages.Response> EditEntityAsync(EntityAddEditModel entityModel) { var response = new Response(); var context = new AdminDbContext(); ValidateEntity(entityModel, response); if (!response.Success) { return response; } var entity = context.Entities.Find(entityModel.Id); entity.TypeId = entityModel.TypeId; entity.Name = entityModel.Name; await context.SaveChangesAsync(); return response; }
public static async Task<Response> AddEntityRelation(AddEntityRelationModel addEntityRelationModel) { var response = ValidateEntityRelation(addEntityRelationModel); if (!response.Success) { return response; } var relation = new Relation() { TypeId = addEntityRelationModel.RelationTypeId }; relation.RelationEntities.Add(new RelationEntity { EntityId = addEntityRelationModel.Id }); relation.RelationEntities.Add(new RelationEntity { EntityId = addEntityRelationModel.OtherEntityId }); var context = new AdminDbContext(); context.Relations.Add(relation); await context.SaveChangesAsync(); return response; }
public static async Task<Response> UpdateUserAsync(AddUserModel registerModel) { var response = new Response(); ValidateUser(registerModel, response); if (!response.Success) { return response; } else { var context = new AdminDbContext(); var user = context.Users.Find(registerModel.Id); if (user != null) { user.Email = registerModel.Email; if (!string.IsNullOrEmpty(registerModel.Password)) { user.Password = GenerateHashWithSalt(registerModel.Password, registerModel.Email); } user.PasswordSalt = Path.GetRandomFileName(); user.RegisterDate = registerModel.RegisterDate; user.Active = registerModel.Active; await context.SaveChangesAsync(); } } return response; }
public static async Task<Response> DeleteUserAsync(long id) { var response = new Response(); var context = new AdminDbContext(); var user = await context.Users.FindAsync(id); context.Users.Remove(user); await context.SaveChangesAsync(); return response; }