public JsonResult GetProductChannelTypes(int bookingChannelTypeId) { ProductChannelTypeRepository productChannelTypeRepository = new ProductChannelTypeRepository(); var result = productChannelTypeRepository.GetProductChannelTypesForBookingChannel(bookingChannelTypeId); return(Json(result)); }
// GET: /Edit public ActionResult Edit(int id) { //Get BookingChannel BookingChannel bookingChannel = new BookingChannel(); bookingChannel = bookingChannelRepository.BookingChannel(id); //Check Exists if (bookingChannel == null) { ViewData["ActionMethod"] = "EditGet"; return(View("RecordDoesNotExistError")); } //Access Rights RolesRepository rolesRepository = new RolesRepository(); if (!rolesRepository.HasWriteAccessToClientSubUnit(bookingChannel.ClientSubUnitGuid) || !hierarchyRepository.AdminHasDomainWriteAccess(groupName)) { ViewData["Message"] = "You do not have access to this item"; return(View("Error")); } BookingChannelVM bookingChannelVM = new BookingChannelVM(); bookingChannelVM.BookingChannel = bookingChannel; //Get ClientSubUnit ClientSubUnit clientSubUnit = new ClientSubUnit(); clientSubUnit = clientSubUnitRepository.GetClientSubUnit(bookingChannel.ClientSubUnitGuid); bookingChannelVM.ClientSubUnit = clientSubUnit; //Booking Channel Types BookingChannelTypeRepository bookingChannelTypeRepository = new BookingChannelTypeRepository(); if (bookingChannelVM.BookingChannel.BookingChannelTypeId != null) { bookingChannelVM.BookingChannelTypes = new SelectList( bookingChannelTypeRepository.GetAllBookingChannelTypes().ToList(), "BookingChannelTypeId", "BookingChannelTypeDescription", bookingChannelVM.BookingChannel.BookingChannelTypeId ); } else { bookingChannelVM.BookingChannelTypes = new SelectList( bookingChannelTypeRepository.GetAllBookingChannelTypes().ToList(), "BookingChannelTypeId", "BookingChannelTypeDescription" ); } //Channel Products ProductChannelTypeRepository productChannelTypeRepository = new ProductChannelTypeRepository(); int bookingChannelTypeId = (bookingChannelVM.BookingChannel.BookingChannelTypeId != null) ? bookingChannelVM.BookingChannel.BookingChannelTypeId.Value : 1; bookingChannelVM.ProductChannelTypes = new SelectList( productChannelTypeRepository.GetProductChannelTypesForBookingChannel(bookingChannelTypeId).ToList(), "ProductChannelTypeId", "ProductChannelTypeDescription", bookingChannelVM.BookingChannel.ProductChannelTypeId ); //Desktop Used Types DesktopUsedTypeRepository desktopUsedTypeRepository = new DesktopUsedTypeRepository(); if (bookingChannelVM.BookingChannel.DesktopUsedTypeId != null) { bookingChannelVM.DesktopUsedTypes = new SelectList( desktopUsedTypeRepository.GetAllDesktopUsedTypes().ToList(), "DesktopUsedTypeId", "DesktopUsedTypeDescription", bookingChannelVM.BookingChannel.DesktopUsedTypeId ); } else { bookingChannelVM.DesktopUsedTypes = new SelectList( desktopUsedTypeRepository.GetAllDesktopUsedTypes().ToList(), "DesktopUsedTypeId", "DesktopUsedTypeDescription" ); } //Content Booked Items ContentBookedItemRepository contentBookedItemRepository = new ContentBookedItemRepository(); List <ContentBookedItem> contentBookedItems = contentBookedItemRepository.GetBookingChannelContentBookedItems(bookingChannelVM.BookingChannel.BookingChannelId).ToList(); ProductRepository productRepository = new ProductRepository(); IEnumerable <SelectListItem> defaultProducts = new SelectList(productRepository.GetAllProducts().ToList(), "ProductId", "ProductName"); List <SelectListItem> contentBookedItemsSelected = new List <SelectListItem>(); foreach (SelectListItem item in defaultProducts) { bool selected = false; foreach (ContentBookedItem contentBookedItem in contentBookedItems) { if (item.Value == contentBookedItem.Product.ProductId.ToString()) { selected = true; } } contentBookedItemsSelected.Add( new SelectListItem() { Text = item.Text, Value = item.Value, Selected = selected } ); } bookingChannelVM.ContentBookedItemsSelected = contentBookedItemsSelected; //GDS GDSRepository GDSRepository = new GDSRepository(); bookingChannelVM.GDSList = new SelectList(GDSRepository.GetAllGDSsExceptALL().OrderBy(x => x.GDSName).ToList(), "GDSCode", "GDSName"); //Show Edit Form return(View(bookingChannelVM)); }