Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task <ActionResult> FacilityIndex()
        {
            try
            {
                if (!CheckUserAuthorization())
                {
                    return(RedirectToAction("Login", "Home"));
                }

                List <Facility> model = new List <Facility>();
                model = await obj.GetFacilityList();

                return(View(model));
            }
            // Redirect user to Help if an error occurs
            catch (Exception e)
            {
                Logger.Error(e, "Error Level");
                Logger.Fatal(e, "Fatal Level");

                TempData["tempErrorMessage"] = e.Message.ToString();
                return(RedirectToAction("Error", "Help"));
            }
        }
Ejemplo n.º 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"));
            }
        }