private void RemoveEquipmentFromOrder(EquipmentFromOrder equipmentFromOrder, AppDbContext db) { var equipment = (from eq in db.EquipmentsFromOrder where eq.Id == equipmentFromOrder.Id select eq).Single(); if (equipment.Count == equipmentFromOrder.Count) { db.EquipmentsFromOrder.Remove(equipment); } else { equipment.Count -= equipmentFromOrder.Count; } }
private async Task AddEqipmentInRent(EquipmentFromOrder equipment, AppDbContext db) { if (equipment.IsPartnerEquipment) { return; } var equipmentInRent = await(from eq in db.EquipmentsInRent where eq.Name == equipment.Name && eq.EndDate == equipment.EndDate select eq).FirstOrDefaultAsync(); if (equipmentInRent != null) { equipmentInRent.Count += equipment.Count; } else { await db.EquipmentsInRent.AddAsync(equipment); } }
private async Task TakeEquipment(EquipmentFromOrder equipment, AppDbContext db) { if (equipment.IsPartnerEquipment) { return; } var avalibleEquipment = await(from equipmentInStock in db.EquipmentsInStock where equipmentInStock.Name == equipment.Name select equipmentInStock).SingleAsync(); if (avalibleEquipment.Count >= equipment.Count) { avalibleEquipment.Count = avalibleEquipment.Count - equipment.Count; } else { int notEnoughCount = equipment.Count - avalibleEquipment.Count; avalibleEquipment.Count = 0; await TakeEquipmentFromRent(equipment.Name, notEnoughCount, equipment.StartDate, equipment.EndDate, db); } }
private void RemoveEquipmentFromRent(EquipmentFromOrder equipment, AppDbContext db) { if (equipment.IsPartnerEquipment) { return; } EquipmentInRent equipmentInRent = (from eq in db.EquipmentsInRent where eq.Name == equipment.Name && eq.StartDate == equipment.StartDate && eq.EndDate == equipment.EndDate select eq).Single(); if (equipmentInRent.Count > equipment.Count) { equipmentInRent.Count = equipmentInRent.Count - equipment.Count; AddEquipmentToAvalible(equipment.Name, equipment.Count, db); } else { db.EquipmentsInRent.Remove(equipmentInRent); AddEquipmentToAvalible(equipmentInRent.Name, equipmentInRent.Count, db); } }