private void AddMaterialsRequest(Location location) { var materialsRequest = new MaterialsRequest { Customer = "За взносы", IsPayed = true, LocationId = location.Id }; _db.MaterialsRequests.Add(materialsRequest); _db.SaveChanges(); var materialsForPayedRequests = _db.Materials.Where(x => x.AmountPerPayedRequestInLocation > 0).ToList(); foreach (var material in materialsForPayedRequests) { var singleMaterialRequest = new SingleMaterialRequest { MaterialId = material.Id, MaterialsRequestId = materialsRequest.Id, QuantityOrdered = location.RequestsPayed * material.AmountPerPayedRequestInLocation, QuantityServed = 0, }; _db.SingleMaterialRequests.Add(singleMaterialRequest); _db.SaveChanges(); } }
private void AddSingleMaterialRequests(string materialName) { var material = _db.Materials.First(x => x.Name == materialName); var locationsWithPlayers = _db.Locations.Where(x => x.RequestsPayed > 0).ToList(); foreach (var location in locationsWithPlayers) { var materialRequest = _db.MaterialsRequests .FirstOrDefault(x => x.IsPayed && x.LocationId == location.Id && x.Customer == "За взносы"); if (materialRequest != null) { var singleMaterialRequest = new SingleMaterialRequest { QuantityOrdered = material.AmountPerPayedRequestInLocation * location.RequestsPayed, QuantityServed = 0, MaterialId = material.Id, MaterialsRequestId = materialRequest.Id, }; _db.SingleMaterialRequests.Add(singleMaterialRequest); _db.SaveChanges(); } } }