Example #1
0
        public ActionResult Add(AddEditRoomDataViewModel vModel)
        {
            string message = string.Empty;
            var authedUser = UserManager.FindById(User.Identity.GetUserId());

            var newObj = new RoomData();
            newObj.Name = vModel.NewName;
            newObj.Model = new DimensionalModel(vModel.DimensionalModelHeight, vModel.DimensionalModelLength, vModel.DimensionalModelWidth
                                , vModel.DimensionalModelVacuity, vModel.DimensionalModelCavitation);

            var mediumId = vModel.Medium;
            var medium = BackingDataCache.Get<IMaterial>(mediumId);

            if (medium != null)
            {
                newObj.Medium = medium;

                var zoneId = vModel.Zone;
                var zone = BackingDataCache.Get<IZone>(zoneId);

                if (zone != null)
                {
                    newObj.ZoneAffiliation = zone;

                    if (newObj.Create() == null)
                        message = "Error; Creation failed.";
                    else
                    {
                        LoggingUtility.LogAdminCommandUsage("*WEB* - AddRoomData[" + newObj.ID.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                        message = "Creation Successful.";
                    }
                }
                else
                    message = "You must include a valid Zone.";
            }
            else
                message = "You must include a valid Medium material.";

            return RedirectToAction("Index", new { Message = message });
        }
        public ActionResult AddWithRoom(AddEditPathwayDataViewModel vModel, long id)
        {
            string message = string.Empty;
            var authedUser = UserManager.FindById(User.Identity.GetUserId());

            var newObj = new PathwayData();
            newObj.Name = vModel.NewName;
            newObj.AudibleStrength = vModel.AudibleStrength;
            newObj.AudibleToSurroundings = vModel.AudibleToSurroundings;
            newObj.DegreesFromNorth = vModel.DegreesFromNorth;
            newObj.FromLocationID = vModel.ToLocationID.ToString();
            newObj.FromLocationType = "RoomData";
            newObj.MessageToActor = vModel.MessageToActor;
            newObj.MessageToDestination = vModel.MessageToDestination;
            newObj.MessageToOrigin = vModel.MessageToOrigin;
            newObj.ToLocationID = vModel.ToLocationID.ToString();
            newObj.ToLocationType = "RoomData";
            newObj.VisibleStrength = vModel.VisibleStrength;
            newObj.VisibleToSurroundings = vModel.VisibleToSurroundings;

            var materialParts = new Dictionary<string, IMaterial>();
            if (vModel.ModelPartNames != null)
            {
                int nameIndex = 0;
                foreach (var partName in vModel.ModelPartNames)
                {
                    if (!string.IsNullOrWhiteSpace(partName))
                    {
                        if (vModel.ModelPartMaterials.Count() <= nameIndex)
                            break;

                        var material = BackingDataCache.Get<Material>(vModel.ModelPartMaterials[nameIndex]);

                        if (material != null && !string.IsNullOrWhiteSpace(partName))
                            materialParts.Add(partName, material);
                    }

                    nameIndex++;
                }
            }

            var dimModel = BackingDataCache.Get<DimensionalModelData>(vModel.DimensionalModelId);
            bool validData = true;

            if (dimModel == null)
            {
                message = "Choose a valid dimensional model.";
                validData = false;
            }

            if (dimModel.ModelPlanes.Any(plane => !materialParts.ContainsKey(plane.TagName)))
            {
                message = "You need to choose a material for each Dimensional Model planar section. (" + string.Join(",", dimModel.ModelPlanes.Select(plane => plane.TagName)) + ")";
                validData = false;
            }

            if (validData)
            {
                newObj.Model = new DimensionalModel(vModel.DimensionalModelHeight, vModel.DimensionalModelLength, vModel.DimensionalModelWidth,
                    vModel.DimensionalModelVacuity, vModel.DimensionalModelCavitation, vModel.DimensionalModelId, materialParts);

                if (newObj.Create() == null)
                    message = "Error; Creation failed.";
                else
                {
                    LoggingUtility.LogAdminCommandUsage("*WEB* - AddPathwayWithRoom[" + newObj.ID.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                    message = "Creation Successful.";
                }
            }

            string roomMessage = string.Empty;
            var newRoom = new RoomData();
            newRoom.Name = vModel.NewRoomModel.NewName;
            newRoom.Model = new DimensionalModel(vModel.NewRoomModel.DimensionalModelHeight, vModel.NewRoomModel.DimensionalModelLength, vModel.NewRoomModel.DimensionalModelWidth
                                , vModel.NewRoomModel.DimensionalModelVacuity, vModel.NewRoomModel.DimensionalModelCavitation);

            var mediumId = vModel.NewRoomModel.Medium;
            var medium = BackingDataCache.Get<IMaterial>(mediumId);

            if (medium != null)
            {
                newRoom.Medium = medium;

                var zoneId = vModel.NewRoomModel.Zone;
                var zone = BackingDataCache.Get<IZone>(zoneId);

                if (zone != null)
                {
                    newRoom.ZoneAffiliation = zone;

                    if (newRoom.Create() == null)
                        roomMessage = "Error; Creation failed.";
                    else
                    {
                        LoggingUtility.LogAdminCommandUsage("*WEB* - AddRoomDataWithPathway[" + newRoom.ID.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                        roomMessage = "Creation Successful.";
                    }
                }
                else
                    roomMessage = "You must include a valid Zone.";
            }
            else
                roomMessage = "You must include a valid Medium material.";

            var result = new ContentResult();
            result.Content = message + "|" + roomMessage;

            return result;
        }
        public ActionResult AddRoomData(AddEditRoomDataViewModel vModel)
        {
            string message = string.Empty;
            var authedUser = UserManager.FindById(User.Identity.GetUserId());

            var newObj = new RoomData();
            newObj.Name = vModel.NewName;
            newObj.Model = new DimensionalModel(vModel.DimensionalModelHeight, vModel.DimensionalModelLength, vModel.DimensionalModelWidth);

            if (vModel.BorderMaterials != null)
            {
                int index = 0;
                foreach (var materialId in vModel.BorderMaterials)
                {
                    if (materialId > 0)
                    {
                        if (vModel.BorderNames.Count() <= index)
                            break;

                        var name = vModel.BorderNames[index];
                        var material = ReferenceWrapper.GetOne<IMaterial>(materialId);

                        if (material != null && !string.IsNullOrWhiteSpace(name) && !newObj.Borders.ContainsKey(name))
                            newObj.Borders.Add(name, material);
                    }

                    index++;
                }
            }

            var mediumId = vModel.Medium;
            var medium = ReferenceWrapper.GetOne<IMaterial>(mediumId);

            if (medium != null)
            {
                newObj.Medium = medium;

                var zoneId = vModel.Zone;
                var zone = ReferenceWrapper.GetOne<IZone>(zoneId);

                if (zone != null)
                {
                    newObj.ZoneAffiliation = zone;

                    if (newObj.Create() == null)
                        message = "Error; Creation failed.";
                    else
                    {
                        LoggingUtility.LogAdminCommandUsage("*WEB* - AddRoomData[" + newObj.ID.ToString() + "]", authedUser.GameAccount.GlobalIdentityHandle);
                        message = "Creation Successful.";
                    }
                }
                else
                    message = "You must include a valid Zone.";
            }
            else
                message = "You must include a valid Medium material.";

            return RedirectToAction("ManageRoomData", new { Message = message });
        }