public async Task <Unit> Handle(CreateLocationIndustryCommand request, CancellationToken cancellationToken) { var location = await this.context.Locations.FindAsync(request.LocationId); if (location == null || location.IsDeleted == true) { throw new CreateFailureException(GConst.LocationIndustry, request.LocationId, string.Format(GConst.RefereceException, GConst.LocationLower, request.LocationId)); } var industry = await this.context.Industries.FindAsync(request.IndustryId); if (industry == null || industry.IsDeleted == true) { throw new CreateFailureException(GConst.LocationIndustry, request.IndustryId, string.Format(GConst.RefereceException, GConst.IndustryLower, request.IndustryId)); } bool isActive = location.Employees.Any(x => x.EmployeeServices.Any(y => y.Service.IndustryId == industry.Id)); var locationIndustry = new LocationIndustry { LocationId = location.Id, Location = location, IndustryId = industry.Id, Industry = industry, Description = request.Description, IsActive = isActive, CreatedOn = DateTime.UtcNow }; this.context.LocationIndustries.Add(locationIndustry); await this.context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public static void AddLocationIndustry(StudioDbContext context, int industryId, int locationId) { var locationIndustry = new LocationIndustry { IndustryId = industryId, LocationId = locationId }; context.LocationIndustries.Add(locationIndustry); context.SaveChanges(); }
public static void AddLocationIndustries(StudioDbContext context) { var locationId = CommandArrangeHelper.GetLocationId(context, null, null); var industryId = CommandArrangeHelper.GetIndustryId(context); var locationIndustry = new LocationIndustry { LocationId = locationId, IndustryId = industryId, Description = "Good!" }; context.LocationIndustries.Add(locationIndustry); context.SaveChanges(); }
public static LocationIndustryPageViewModel Create(LocationIndustry locationIndustry) { return(Projection.Compile().Invoke(locationIndustry)); }