示例#1
0
        public async Task <ViewResult> SaveMapAsync(TemplateModelMap templateModel)
        {
            MapUtilities util = new MapUtilities(host);

            // if user has selected "---" dropdown option
            if (templateModel.Maps[0].Building.Contains("-2") || templateModel.Maps[1].Building.Contains("-2"))
            {
                ModelState.AddModelError("", "Please select a building");
            }

            // if room number does not exist in the database
            else if (!util.CheckRoom(templateModel.Maps))
            {
                ModelState.AddModelError("", "Invalid Room Number");
            }

            // main driver for map creation
            if (ModelState.IsValid)
            {
                // code to generate template
                try
                {
                    List <string> fileNames = new List <string>();
                    //fileNames = await util.CreateMap(templateModel.Maps);
                    try
                    {
                        fileNames = await util.EditMap(templateModel.Maps);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    TempData["Maps"]       = fileNames;
                    TempData["Directions"] = util.Directions(templateModel.Maps); // directions
                    TempData["Times"]      = util.TimeQuery(templateModel.Maps);  // time
                }
                catch
                {
                    Console.WriteLine("something went wrong");
                }
                return(View("Result", templateModel));
            }
            else // else model errors out
            {
                ModelState.AddModelError("", "");
                return(View("MapBuilder", templateModel));
            }
        }