Пример #1
0
        public ActionResult AddEditZoneDescriptive(string birthMark, LiveOccurrenceViewModel vModel)
        {
            string          message    = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            IZone obj = LiveCache.Get <IZone>(new LiveCacheKey(typeof(Zone), birthMark));

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

            ISensoryEvent existingOccurrence = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                                                               occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            if (existingOccurrence == null)
            {
                existingOccurrence = new SensoryEvent(vModel.SensoryEventDataObject.SensoryType)
                {
                    Strength = vModel.SensoryEventDataObject.Strength,
                    Event    = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                          vModel.SensoryEventDataObject.Event.Role,
                                          vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                    {
                        Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                    }
                };
            }
            else
            {
                existingOccurrence.Strength    = vModel.SensoryEventDataObject.Strength;
                existingOccurrence.SensoryType = vModel.SensoryEventDataObject.SensoryType;
                existingOccurrence.Event       = new Lexica(vModel.SensoryEventDataObject.Event.Type,
                                                            vModel.SensoryEventDataObject.Event.Role,
                                                            vModel.SensoryEventDataObject.Event.Phrase, new LexicalContext(null))
                {
                    Modifiers = vModel.SensoryEventDataObject.Event.Modifiers
                };
            }

            obj.Descriptives.RemoveWhere(occurrence => occurrence.Event.Role == vModel.SensoryEventDataObject.Event.Role &&
                                         occurrence.Event.Phrase.Equals(vModel.SensoryEventDataObject.Event.Phrase, StringComparison.InvariantCultureIgnoreCase));

            obj.Descriptives.Add(existingOccurrence);

            if (obj.Save())
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - LIVE DATA - Zone AddEditDescriptive[" + obj.BirthMark + "]", authedUser.GameAccount.GlobalIdentityHandle);
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return(RedirectToRoute("ModalErrorOrClose", new { Message = message }));
        }
Пример #2
0
        public ActionResult AddEditZoneDescriptive(string birthMark, short descriptiveType, string phrase)
        {
            string message = string.Empty;

            IZone obj = LiveCache.Get <IZone>(new LiveCacheKey(typeof(Zone), birthMark));

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

            LiveOccurrenceViewModel vModel = new LiveOccurrenceViewModel
            {
                AuthedUser    = UserManager.FindById(User.Identity.GetUserId()),
                DataObject    = obj,
                AdminTypeName = "LiveAdmin/Zone"
            };

            if (descriptiveType > -1)
            {
                GrammaticalType grammaticalType = (GrammaticalType)descriptiveType;
                vModel.SensoryEventDataObject = obj.Descriptives.FirstOrDefault(occurrence => occurrence.Event.Role == grammaticalType &&
                                                                                occurrence.Event.Phrase.Equals(phrase, StringComparison.InvariantCultureIgnoreCase));
            }

            if (vModel.SensoryEventDataObject != null)
            {
                vModel.LexicaDataObject = vModel.SensoryEventDataObject.Event;
            }
            else
            {
                vModel.SensoryEventDataObject = new SensoryEvent
                {
                    Event = new Lexica()
                };
            }

            return(View("~/Views/LiveAdmin/Zone/SensoryEvent.cshtml", "_chromelessLayout", vModel));
        }