Esempio n. 1
0
        private void OpenRequest(object sender)
        {
            var selectedItem = sender as RequestForListDto;

            if (selectedItem == null)
            {
                return;
            }
            var request = _requestService.GetRequest(selectedItem.Id);

            if (request == null)
            {
                MessageBox.Show("Произошла непредвиденная ошибка!");
                return;
            }

            var viewModel = new RequestDialogViewModel();
            var view      = new RequestDialog(viewModel);

            viewModel.SetView(view);
            viewModel.RequestId      = request.Id;
            viewModel.SelectedCity   = viewModel.CityList.SingleOrDefault(i => i.Id == request.Address.CityId);
            viewModel.SelectedStreet = viewModel.StreetList.SingleOrDefault(i => i.Id == request.Address.StreetId);
            viewModel.SelectedHouse  = viewModel.HouseList.SingleOrDefault(i => i.Id == request.Address.HouseId);
            viewModel.SelectedFlat   = viewModel.FlatList.SingleOrDefault(i => i.Id == request.Address.Id);
            viewModel.Floor          = request.Floor;
            viewModel.Entrance       = request.Entrance;
            viewModel.FromTime       = request.FromTime;
            viewModel.ToTime         = request.ToTime;
            var requestModel = viewModel.RequestList.FirstOrDefault();

            requestModel.SelectedParentService = requestModel.ParentServiceList.SingleOrDefault(i => i.Id == request.Type.ParentId);
            requestModel.SelectedService       = requestModel.ServiceList.SingleOrDefault(i => i.Id == request.Type.Id);
            requestModel.Description           = request.Description;
            requestModel.IsChargeable          = request.IsChargeable;
            requestModel.IsImmediate           = request.IsImmediate;
            requestModel.IsBadWork             = request.IsBadWork;
            requestModel.IsRetry = request.IsRetry;
            var sched = _requestService.GetScheduleTaskByRequestId(request.Id);

            requestModel.SelectedAppointment = sched != null ? new Appointment()
            {
                Id        = sched.Id,
                RequestId = sched.RequestId,
                StartTime = sched.FromDate,
                EndTime   = sched.ToDate,
            } : null;
            requestModel.OpenAppointment = requestModel.SelectedAppointment;
            //requestModel.Gatanty = request.Warranty;
            requestModel.SelectedGaranty = requestModel.GarantyList.FirstOrDefault(g => g.Id == request.GarantyId);

            requestModel.RequestCreator   = request.CreateUser.ShortName;
            requestModel.RequestDate      = request.CreateTime;
            requestModel.RequestState     = request.State.Description;
            requestModel.SelectedMaster   = request.MasterId.HasValue ? _requestService.GetWorkerById(request.MasterId.Value) : null;
            requestModel.SelectedExecuter = request.ExecuterId.HasValue ? _requestService.GetWorkerById(request.ExecuterId.Value) : null;

            requestModel.SelectedEquipment = requestModel.EquipmentList.SingleOrDefault(e => e.Id == request.Equipment.Id);
            requestModel.RequestId         = request.Id;
            requestModel.Rating            = request.Rating;
            requestModel.AlertTime         = request.AlertTime;
            if (request.ServiceCompanyId.HasValue)
            {
                requestModel.SelectedCompany = requestModel.CompanyList.FirstOrDefault(c => c.Id == request.ServiceCompanyId.Value);
            }
            if (request.ExecuteDate.HasValue && request.ExecuteDate.Value.Date > DateTime.MinValue)
            {
                requestModel.SelectedDateTime = request.ExecuteDate.Value.Date;
                requestModel.SelectedPeriod   = requestModel.PeriodList.SingleOrDefault(i => i.Id == request.PeriodId);
            }
            requestModel.TermOfExecution = request.TermOfExecution;
            viewModel.ContactList        = new ObservableCollection <ContactDto>(request.Contacts);
            view.Show();
        }