Пример #1
0
        public ActionResult Add(long localeId)
        {
            ILocaleTemplate myLocale = TemplateCache.Get <ILocaleTemplate>(localeId);

            if (myLocale == null)
            {
                return(RedirectToAction("Index", new { Message = "Invalid Locale" }));
            }

            AddEditRoomTemplateViewModel vModel = new AddEditRoomTemplateViewModel
            {
                AuthedUser     = UserManager.FindById(User.Identity.GetUserId()),
                ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                ValidModels    = TemplateCache.GetAll <IDimensionalModelData>(),
                ValidZones     = TemplateCache.GetAll <IZoneTemplate>(),
                ValidRooms     = TemplateCache.GetAll <IRoomTemplate>(),
                ValidLocales   = TemplateCache.GetAll <ILocaleTemplate>().Where(locale => locale.Id != localeId),
                ZonePathway    = new PathwayTemplate()
                {
                    Destination = myLocale.ParentLocation
                },
                LocaleRoomPathway = new PathwayTemplate(),
                LocaleRoomPathwayDestinationLocale = new LocaleTemplate(),
                DataObject = new RoomTemplate()
                {
                    ParentLocation = myLocale
                }
            };

            return(View("~/Views/GameAdmin/Room/Add.cshtml", "_chromelessLayout", vModel));
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            string        message = string.Empty;
            IRoomTemplate obj     = TemplateCache.Get <IRoomTemplate>(id);

            if (obj == null)
            {
                message = "That does not exist";
                return(RedirectToRoute("ErrorOrClose", new { Message = message }));
            }

            AddEditRoomTemplateViewModel vModel = new AddEditRoomTemplateViewModel
            {
                AuthedUser       = UserManager.FindById(User.Identity.GetUserId()),
                ValidMaterials   = TemplateCache.GetAll <IMaterial>(),
                ValidZones       = TemplateCache.GetAll <IZoneTemplate>(),
                ValidLocales     = TemplateCache.GetAll <ILocaleTemplate>().Where(locale => locale.Id != obj.ParentLocation.Id),
                ValidLocaleRooms = TemplateCache.GetAll <IRoomTemplate>().Where(room => room.Id != obj.Id && room.ParentLocation.Id == obj.ParentLocation.Id),
                ValidRooms       = TemplateCache.GetAll <IRoomTemplate>().Where(room => room.Id != obj.Id),
                ValidModels      = TemplateCache.GetAll <IDimensionalModelData>(),
                DataObject       = obj,
            };

            IPathwayTemplate zoneDestination = obj.GetZonePathways().FirstOrDefault();

            if (zoneDestination != null)
            {
                vModel.ZonePathway = zoneDestination;
            }
            else
            {
                vModel.ZonePathway = new PathwayTemplate()
                {
                    Destination = obj.ParentLocation.ParentLocation, Origin = obj
                };
            }

            IPathwayTemplate localeRoomPathway = obj.GetLocalePathways().FirstOrDefault();

            if (localeRoomPathway != null)
            {
                vModel.LocaleRoomPathway = localeRoomPathway;
                vModel.LocaleRoomPathwayDestinationLocale = ((IRoomTemplate)localeRoomPathway.Destination).ParentLocation;
                vModel.ValidLocaleRooms = TemplateCache.GetAll <IRoomTemplate>().Where(room => localeRoomPathway.Id == room.ParentLocation.Id);
            }
            else
            {
                vModel.LocaleRoomPathway = new PathwayTemplate()
                {
                    Origin = obj
                };
                vModel.LocaleRoomPathwayDestinationLocale = new LocaleTemplate();
            }


            return(View("~/Views/GameAdmin/Room/Edit.cshtml", "_chromelessLayout", vModel));
        }
Пример #3
0
        public ActionResult Edit(int id, AddEditRoomTemplateViewModel vModel)
        {
            ApplicationUser  authedUser        = UserManager.FindById(User.Identity.GetUserId());
            IPathwayTemplate zoneDestination   = null;
            IPathwayTemplate localeRoomPathway = null;

            IRoomTemplate obj = TemplateCache.Get <IRoomTemplate>(id);

            if (obj == null)
            {
                string message = "That does not exist";
                return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
            }

            obj.Name      = vModel.DataObject.Name;
            obj.Medium    = vModel.DataObject.Medium;
            obj.Qualities = vModel.DataObject.Qualities;

            if (vModel.ZonePathway?.Destination != null && !string.IsNullOrWhiteSpace(vModel.ZonePathway.Name))
            {
                IZoneTemplate destination = TemplateCache.Get <IZoneTemplate>(vModel.ZonePathway.Destination.Id);
                zoneDestination = obj.GetZonePathways().FirstOrDefault();

                if (zoneDestination == null)
                {
                    zoneDestination = new PathwayTemplate()
                    {
                        DegreesFromNorth = vModel.ZonePathway.DegreesFromNorth,
                        Name             = vModel.ZonePathway.Name,
                        Origin           = obj,
                        Destination      = destination,
                        InclineGrade     = vModel.ZonePathway.InclineGrade,
                        Model            = vModel.ZonePathway.Model
                    };
                }
                else
                {
                    zoneDestination.Model        = vModel.ZonePathway.Model;
                    zoneDestination.Name         = vModel.ZonePathway.Name;
                    zoneDestination.InclineGrade = vModel.ZonePathway.InclineGrade;

                    //We switched zones, this makes things more complicated
                    if (zoneDestination.Id != vModel.ZonePathway.Destination.Id)
                    {
                        zoneDestination.Destination = destination;
                    }
                }
            }

            if (vModel.LocaleRoomPathwayDestination != null && !string.IsNullOrWhiteSpace(vModel.LocaleRoomPathwayDestination.Name))
            {
                IRoomTemplate destination = TemplateCache.Get <IRoomTemplate>(vModel.LocaleRoomPathwayDestination.Id);
                localeRoomPathway = obj.GetLocalePathways().FirstOrDefault();

                if (localeRoomPathway == null)
                {
                    localeRoomPathway = new PathwayTemplate()
                    {
                        DegreesFromNorth = vModel.LocaleRoomPathway.DegreesFromNorth,
                        Name             = vModel.LocaleRoomPathway.Name,
                        Origin           = obj,
                        Destination      = destination,
                        InclineGrade     = vModel.LocaleRoomPathway.InclineGrade,
                        Model            = vModel.LocaleRoomPathway.Model
                    };
                }
                else
                {
                    localeRoomPathway.Model        = vModel.LocaleRoomPathway.Model;
                    localeRoomPathway.Name         = vModel.LocaleRoomPathway.Name;
                    localeRoomPathway.InclineGrade = vModel.LocaleRoomPathway.InclineGrade;
                    localeRoomPathway.Destination  = destination;
                }
            }

            if (obj.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                if (zoneDestination != null)
                {
                    zoneDestination.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                if (localeRoomPathway != null)
                {
                    localeRoomPathway.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                LoggingUtility.LogAdminCommandUsage("*WEB* - EditRoomTemplate[" + obj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
            }

            return(RedirectToRoute("ModalErrorOrClose"));
        }
Пример #4
0
        public ActionResult Add(long localeId, AddEditRoomTemplateViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());
            ILocaleTemplate locale     = TemplateCache.Get <ILocaleTemplate>(localeId);

            IRoomTemplate newObj = vModel.DataObject;

            newObj.ParentLocation = locale;
            newObj.Coordinates    = new Coordinate(0, 0, 0); //TODO: fix this

            IPathwayTemplate zoneDestination = null;

            if (vModel.ZonePathway?.Destination != null && !string.IsNullOrWhiteSpace(vModel.ZonePathway.Name))
            {
                IZoneTemplate destination = TemplateCache.Get <IZoneTemplate>(vModel.ZonePathway.Destination.Id);
                zoneDestination = new PathwayTemplate()
                {
                    DegreesFromNorth = -1,
                    Name             = vModel.ZonePathway.Name,
                    Origin           = newObj,
                    Destination      = destination,
                    InclineGrade     = vModel.ZonePathway.InclineGrade,
                    Model            = vModel.ZonePathway.Model
                };
            }

            IPathwayTemplate localeRoomPathway = null;

            if (vModel.LocaleRoomPathwayDestination != null && !string.IsNullOrWhiteSpace(vModel.LocaleRoomPathwayDestination.Name))
            {
                IRoomTemplate destination = TemplateCache.Get <IRoomTemplate>(vModel.LocaleRoomPathwayDestination.Id);
                localeRoomPathway = new PathwayTemplate()
                {
                    DegreesFromNorth = vModel.LocaleRoomPathway.DegreesFromNorth,
                    Name             = vModel.LocaleRoomPathway.Name,
                    Origin           = newObj,
                    Destination      = destination,
                    InclineGrade     = vModel.LocaleRoomPathway.InclineGrade,
                    Model            = vModel.LocaleRoomPathway.Model
                };
            }


            if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
            {
                if (zoneDestination != null)
                {
                    zoneDestination.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                if (localeRoomPathway != null)
                {
                    localeRoomPathway.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                }

                message = "Error; Creation failed.";
            }
            else
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - AddRoomTemplate[" + newObj.Id.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }