public async Task Consume(ConsumeContext <IProjectAdded> context) { var project = new ProjectModel(context.Message.Id) { Name = context.Message.Name, Status = context.Message.Status }; _context.Projects.Add(project); await _context.SaveChangesAsync(); }
public async Task Consume(ConsumeContext <IJobAdded> context) { var job = new JobModel(context.Message.Id) { Description = context.Message.Name, Status = context.Message.Status, UserId = BaseModel.MakeId(typeof(UserModel), context.Message.UserId), WorkshopId = BaseModel.MakeId(typeof(WorkshopModel), context.Message.WorkshopId), }; _context.Jobs.Add(job); await _context.SaveChangesAsync(); }
public async Task Consume(ConsumeContext <ICityAdded> context) { var city = new CityModel(context.Message.Id) { Name = context.Message.Name, Status = context.Message.Status }; _context.Cities.Add(city); await _context.SaveChangesAsync(); _context.Dispose(); }
public async Task Consume(ConsumeContext <IWorkshopAdded> context) { var workshop = new WorkshopModel(context.Message.Id) { Name = context.Message.Name, Status = context.Message.Status, CityId = BaseModel.MakeId(typeof(CityModel), context.Message.CityId), }; _context.Workshops.Add(workshop); await _context.SaveChangesAsync(); _context.Dispose(); }
public async Task Consume(ConsumeContext <ICustomerAdded> context) { var customer = new CustomerModel(context.Message.Id) { Name = context.Message.Name, Status = context.Message.Status }; _context.Customers.Add(customer); await _context.SaveChangesAsync(); _context.Dispose(); await _messagePublisher.PublishMessageAsync(context.Message); }
public async Task Consume(ConsumeContext <IUserRegistred> context) { var roleId = _context.Roles.Single(x => x.Name.Equals(context.Message.RoleName)).Id; var user = new UserModel(context.Message.Id) { Email = context.Message.Email, PasswordHash = context.Message.PasswordHash, RoleId = roleId, Status = UserStatus.Active, }; _context.Users.Add(user); await _context.SaveChangesAsync(); }
//TODO при запуске проверяет наличие миграций. Пока в топку //public static bool AllMigrationsApplied(this DbContext context) //{ // var applied = context.GetService<IHistoryRepository>() // .GetAppliedMigrations() // .Select(m => m.MigrationId); // var total = context.GetService<IMigrationsAssembly>() // .Migrations // .Select(m => m.Key); // return !total.Except(applied).Any(); //} // Импровизированный Seed как в EF6 public static void EnsureSeeded(this IModelUpdater context) { //Ensure we have some Roles if (!context.Roles.Any()) { var roles = new List <RoleModel>() { new RoleModel(Guid.NewGuid()) { Name = "user", RolePermission = ";user;" }, new RoleModel(Guid.NewGuid()) { Name = "admin", RolePermission = ";admin;" }, }; context.Roles.AddRange(roles); context.SaveChangesAsync(); } }