Пример #1
0
        public async Task <ActionResult> FacilityCreate()
        {
            try
            {
                if (!CheckUserAuthorization())
                {
                    return(RedirectToAction("Login", "Home"));
                }

                List <SelectListItem> placeDropDown = new List <SelectListItem>();
                List <Place>          placeList     = new List <Place>();
                placeList = await obj.GetPlaceList();

                // Loopa igenom kategorier och skapa dropdown
                foreach (var item in placeList)
                {
                    // Skapa nytt objekt vid varje loop
                    SelectListItem temp = new SelectListItem();
                    temp.Text  = item.Name + " | " + item.City;
                    temp.Value = item.Id.ToString();

                    placeDropDown.Add(temp);
                }
                // Listan omvandlas till viewbag
                ViewBag.Fk_Place = placeDropDown;

                return(View());
            }
            catch (Exception e)
            {
                // Add logger
                Logger.Error(e, "Error Level");
                Logger.Fatal(e, "Fatal Level");

                TempData["tempErrorMessage"] = e.Message.ToString();
                return(RedirectToAction("Error", "Help"));
            }
        }
Пример #2
0
        public async Task <ActionResult> CreateEvent()
        {
            try
            {
                if (!CheckUserAuthorization())
                {
                    return(RedirectToAction("Login", "Home"));
                }

                // List of dropdown items
                List <SelectListItem> facilitiesDropDown = new List <SelectListItem>();
                List <SelectListItem> categoryDropDown   = new List <SelectListItem>();

                // Lists for category, facility and places
                List <EventCategory> categoriesList = new List <EventCategory>();
                List <Facility>      facilitiesList = new List <Facility>();
                List <Place>         placeList      = new List <Place>();

                categoriesList = await obj.GetCategoryList();

                facilitiesList = await obj.GetFacilityList();

                placeList = await obj.GetPlaceList();

                // Loopa through the category list to create dropdown
                foreach (var item in categoriesList)
                {
                    // Create new object every loop
                    SelectListItem temp = new SelectListItem();

                    temp.Text  = item.Category_Name;
                    temp.Value = item.Category_Id.ToString();

                    categoryDropDown.Add(temp);
                }

                // Loopa igenom facilities och skapa dropdown
                foreach (var item in facilitiesList)
                {
                    SelectListItem temp  = new SelectListItem();
                    Place          place = new Place();

                    // pick the place which the facility belongs to
                    place = await obj.GetPlaceByID(item.Fk_Place);

                    // Create a string which includes facility and place name for better readability
                    string location = item.Name + " | " + place.Name.ToString() + " | " + place.City.ToString();

                    temp.Text  = location;
                    temp.Value = item.Id.ToString();

                    facilitiesDropDown.Add(temp);
                }

                // Dropdowns created
                ViewBag.Category_Id = categoryDropDown;
                ViewBag.FacilityID  = facilitiesDropDown;

                return(View());
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error Level");
                Logger.Fatal(e, "Fatal Level");

                TempData["tempErrorMessage"] = e.Message.ToString();
                return(RedirectToAction("Error", "Help"));
            }
        }