示例#1
0
        public ActionResult Add(long id, long originRoomId, long destinationRoomId, int degreesFromNorth = 0, int incline = 0)
        {
            //New room or existing room
            if (destinationRoomId.Equals(-1))
            {
                IRoomTemplate origin = TemplateCache.Get <IRoomTemplate>(originRoomId);

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

                    ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                    ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                    ValidRooms     = TemplateCache.GetAll <IRoomTemplate>(),
                    Origin         = origin,
                    DataObject     = new PathwayTemplate()
                    {
                        DegreesFromNorth = degreesFromNorth, InclineGrade = incline
                    },
                    Destination = new RoomTemplate()
                    {
                        ParentLocation = origin.ParentLocation
                    }
                };

                vModel.Destination.ParentLocation = vModel.Origin.ParentLocation;

                return(View("~/Views/GameAdmin/Pathway/AddWithRoom.cshtml", "_chromelessLayout", vModel));
            }
            else
            {
                IRoomTemplate    origin          = TemplateCache.Get <IRoomTemplate>(originRoomId);
                IRoomTemplate    destination     = TemplateCache.Get <IRoomTemplate>(destinationRoomId);
                IPathwayTemplate pathwayTemplate = TemplateCache.Get <IPathwayTemplate>(id);

                if (pathwayTemplate == null)
                {
                    pathwayTemplate = new PathwayTemplate()
                    {
                        Origin = origin, Destination = destination, DegreesFromNorth = degreesFromNorth, InclineGrade = incline
                    };
                }

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

                    ValidMaterials = TemplateCache.GetAll <IMaterial>(),
                    ValidModels    = TemplateCache.GetAll <IDimensionalModelData>().Where(model => model.ModelType == DimensionalModelType.Flat),
                    ValidRooms     = TemplateCache.GetAll <IRoomTemplate>().Where(rm => !rm.Id.Equals(originRoomId)),
                    DataObject     = pathwayTemplate
                };

                return(View("~/Views/GameAdmin/Pathway/AddEdit.cshtml", "_chromelessLayout", vModel));
            }
        }
示例#2
0
        public ActionResult AddWithRoom(AddPathwayWithRoomTemplateViewModel vModel)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IRoomTemplate origin  = TemplateCache.Get <IRoomTemplate>(vModel.Origin.Id);
            IRoomTemplate newRoom = vModel.Destination;

            newRoom.ParentLocation = origin.ParentLocation;

            string message = string.Empty;

            if (newRoom.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) != null)
            {
                IPathwayTemplate newObj = vModel.DataObject;
                newObj.Destination = newRoom;
                newObj.Origin      = origin;

                if (newObj.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                {
                    message = "Error; Creation failed.";
                }
                else
                {
                    if (vModel.CreateReciprocalPath)
                    {
                        PathwayTemplate reversePath = new PathwayTemplate
                        {
                            Name             = newObj.Name,
                            DegreesFromNorth = Utilities.ReverseDirection(newObj.DegreesFromNorth),
                            Origin           = newObj.Destination,
                            Destination      = newObj.Origin,
                            Model            = newObj.Model,
                            InclineGrade     = newObj.InclineGrade * -1
                        };

                        if (reversePath.Create(authedUser.GameAccount, authedUser.GetStaffRank(User)) == null)
                        {
                            message = "Reverse Path creation FAILED. Origin path creation SUCCESS.";
                        }
                    }

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