Ejemplo n.º 1
0
        public ActionResult AddEditLocalePath(long id, long localeId)
        {
            ILocaleTemplate locale = TemplateCache.Get <ILocaleTemplate>(localeId);

            if (locale == null)
            {
                return(RedirectToAction("Edit", new { Message = "Locale is invalid.", id }));
            }

            IEnumerable <IRoomTemplate> validRooms = TemplateCache.GetAll <IRoomTemplate>().Where(rm => rm.ParentLocation.Equals(locale));

            if (validRooms.Count() == 0)
            {
                return(RedirectToAction("Edit", new { Message = "Locale has no rooms.", id }));
            }

            IZoneTemplate origin = TemplateCache.Get <IZoneTemplate>(id);

            IPathwayTemplate existingPathway = origin.GetLocalePathways().FirstOrDefault(path => ((IRoomTemplate)path.Destination).ParentLocation.Equals(locale));

            AddEditZonePathwayTemplateViewModel vModel = new AddEditZonePathwayTemplateViewModel
            {
                AuthedUser = UserManager.FindById(User.Identity.GetUserId()),

                ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                ValidRooms     = validRooms,
            };

            if (existingPathway != null)
            {
                vModel.DataObject      = existingPathway;
                vModel.DestinationRoom = (IRoomTemplate)existingPathway.Destination;
            }
            else
            {
                vModel.DataObject = new PathwayTemplate()
                {
                    Origin = origin
                };
            }

            return(View("~/Views/GameAdmin/Zone/AddEditLocalePath.cshtml", vModel));
        }