Exemplo n.º 1
0
        public async Task <ActionResult> EditModal(long orderId)
        {
            var order = await _orderAppService.GetOrder(orderId);

            var orderStateList            = _lookupAppService.GetOrderStateComboboxItems().Result;
            var orderStateSelectListItems = (from res in orderStateList.Items
                                             select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.OrderStateId.ToString()
            }).ToList();

            var companyList            = _orderAppService.GetCompanyComboboxItems(_session.UserId.GetValueOrDefault()).Result;
            var companySelectListItems = (from res in companyList.Items
                                          select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.CompanyId.ToString()
            }).ToList();

            var firstIdentificationList            = _lookupAppService.GetFirstIdentificationItems().Result;
            var firstIdentificationSelectListItems = (from res in firstIdentificationList.Items
                                                      select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.FirstIdentificationId.ToString()
            }).ToList();

            var secondIdentificationList            = _lookupAppService.GetSecondIdentificationItems().Result;
            var secondIdentificationSelectListItems = (from res in secondIdentificationList.Items
                                                       select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.SecondIdentificationId.ToString()
            }).ToList();

            var timeSlotList            = _lookupAppService.GetTimeSlotComboboxItems().Result;
            var timeSlotSelectListItems = (from res in timeSlotList.Items
                                           select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.TimeSlotId.ToString()
            }).ToList();

            var yesNoList            = _lookupAppService.GetYesNoItems();
            var yesNoSelectListItems = (from res in yesNoList.Items
                                        select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == (order.Followed)
            }).ToList();

            var productTypeList            = _lookupAppService.GetProductTypeItems().Result;
            var dic                        = order.OrdersProductType.ToList().ToDictionary(t => t.ProductTypeId.ToString(), t => t.ProductTypeId);
            var productTypeSelectListItems = (from res in productTypeList.Items
                                              select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = dic.ContainsKey(res.Value)
            }).ToList();

            var paymentStatusList            = _lookupAppService.GetPaymentStatusItems().Result;
            var paymentStatusSelectListItems = (from res in paymentStatusList.Items
                                                select new SelectListItem()
            {
                Text = res.DisplayText,
                Value = res.Value,
                Selected = res.Value == order.PaymentStatusId.ToString()
            }).ToList();

            var model = new EditOrderModalViewModel
            {
                Order                = order,
                OrderState           = orderStateSelectListItems,
                Company              = companySelectListItems,
                FirstIdentification  = firstIdentificationSelectListItems,
                SecondIdentification = secondIdentificationSelectListItems,
                TimeSlot             = timeSlotSelectListItems,
                Followed             = yesNoSelectListItems,
                ProductType          = productTypeSelectListItems,
                PaymentStatus        = paymentStatusSelectListItems
            };

            return(PartialView("_EditModal", model));
        }