private OrderWindowModel CreateModelByOrder(Guid orderGuid) { var order = DbOrderWorker.GetOrder(orderGuid); var additionalServices = DbReferenceWorker.GetAdditionalServiceReference(); foreach (var serviceGuid in order.AdditonalServiceGuids) { var service = additionalServices.SingleOrDefault(x => x.Guid == serviceGuid); if (service != null) { service.Checked = true; } } var model = new OrderWindowModel() { OrderGuid = order.Guid, AdditionalServices = additionalServices, Area = order.Area, BeginRentDate = order.RentBeginDate, EndRentDate = order.RentEndDate, Name = order.Name, TotalCost = order.TotalCost ?? 0, Car = order.Car, IsEdit = true }; return(model); }
private void Hyperlink_Click(object sender, RoutedEventArgs e) { var element = (Hyperlink)sender; var model = (OrderModel)element.DataContext; if (DbOrderWorker.CancelOrder(model.Guid)) { model.StatusString = OrderStatus.Canceled.DescriptionAttr(); } }
private void CompleteBtn_OnClick(object sender, RoutedEventArgs e) { //TODO: Создание нового Заказа var model = (OrderWindowModel)DataContext; var order = new Order { Guid = model.IsEdit ? model.OrderGuid : Guid.NewGuid(), ClientGuid = UserData.User.UserGuid.Value, Car = model.Car, Name = model.Name, OrderDate = DateTime.Now.Date, TotalCost = model.TotalCost, RentBeginDate = model.BeginRentDate.Value, RentEndDate = model.EndRentDate.Value, AdditonalServiceGuids = model.AdditionalServices.Where(x => x.Checked).Select(x => x.Guid).ToList(), Area = model.Area, PaymentType = CashBtn.IsChecked.Value ? PaymentType.Cash : PaymentType.BankCard }; if (model.IsEdit) { if (DbOrderWorker.UpdateOrder(order)) { if (CompleteSuccessed != null) { CompleteSuccessed(this, new EventArgs()); } } } else { if (DbOrderWorker.AddOrder(order)) { order.Car.Status = CarStatus.Busy; DbCarWorker.UpdateCar(model.Car); if (CompleteSuccessed != null) { CompleteSuccessed(this, new EventArgs()); } } } }