private static Car ToShortRentsModel(DB.Cars dbItem, UnitOfWork unitOfWork) { var car = new Car() { Id = dbItem.Id, Color = (CarColor)dbItem.Color, BodyNumber = dbItem.BodyNumber, Enginge = dbItem.Engine, Kpp = dbItem.Kpp, Number = dbItem.Number, Sts = dbItem.Sts, TO = dbItem.TO, Year = dbItem.Year, Insurance = dbItem.Insurance, Model = CarModels.Read(dbItem.Model.Id, unitOfWork), Mileage = dbItem.Mileage, SiteId = dbItem.SiteId, User = Users.Read(dbItem.User.Id, unitOfWork), Deleted = dbItem.Deleted }; if (dbItem.CarRental != null) { car.CarRental = CarRentals.Read(dbItem.CarRental.Id, unitOfWork); } foreach (var rent in dbItem.RentsCollection) { car.Rents.Add(Rents.Read(rent.Id, unitOfWork)); } return(car); }
private static Car ToModel(DB.Cars dbItem, UnitOfWork unitOfWork) { var car = new Car() { Id = dbItem.Id, Color = (CarColor)dbItem.Color, BodyType = (Body)dbItem.Body, BodyNumber = dbItem.BodyNumber, Enginge = dbItem.Engine, Kpp = dbItem.Kpp, Number = dbItem.Number, Sts = dbItem.Sts, TO = dbItem.TO, Year = dbItem.Year, Insurance = dbItem.Insurance, Model = CarModels.Read(dbItem.Model.Id, unitOfWork), Mileage = dbItem.Mileage, SiteId = dbItem.SiteId, User = Users.Read(dbItem.User.Id, unitOfWork), Deleted = dbItem.Deleted }; if (dbItem.CarRental != null) { car.CarRental = CarRentals.Read(dbItem.CarRental.Id, unitOfWork); } foreach (var damage in dbItem.DamagesCollection.Where(damage => !damage.Archive)) { car.Damages.Add(Damages.Read(damage.Id, unitOfWork)); } foreach (var rent in dbItem.RentsCollection) { car.Rents.Add(Rents.Read(rent.Id, unitOfWork)); } foreach (var order in dbItem.OrdersCollection.Where(q => !q.Deleted)) { var cor = new CarOrder() { ClientId = order.Client.Id, DateFrom = order.DateFrom, DateTo = order.DateTo, Id = order.Id, Territory = order.Territory }; foreach (var serv in order.OrderServicesCollection) { cor.Services.Add(Services.Read(serv.Service.Id, unitOfWork)); } car.Orders.Add(cor); } return(car); }