Exemplo n.º 1
0
        private void CreateFieldValueVariantImpl(
            [NotNull] ProjectField field,
            [NotNull] string label,
            [CanBeNull] string description,
            [CanBeNull] string masterDescription,
            [CanBeNull] string programmaticValue)
        {
            var fieldValue = new ProjectFieldDropdownValue()
            {
                Description       = new MarkdownString(description),
                Label             = label,
                IsActive          = true,
                WasEverUsed       = false,
                ProjectId         = field.ProjectId,
                ProjectFieldId    = field.ProjectFieldId,
                Project           = field.Project,
                ProjectField      = field,
                MasterDescription = new MarkdownString(masterDescription),
                ProgrammaticValue = programmaticValue,
            };

            CreateOrUpdateSpecialGroup(fieldValue);

            field.DropdownValues.Add(fieldValue);
        }
Exemplo n.º 2
0
        private void CreateOrUpdateSpecialGroup(ProjectFieldDropdownValue fieldValue)
        {
            var field = fieldValue.ProjectField;

            if (!field.HasSpecialGroup())
            {
                return;
            }
            CreateOrUpdateSpecialGroup(field);

            if (fieldValue.CharacterGroup == null)
            {
                fieldValue.CharacterGroup = new CharacterGroup()
                {
                    AvaiableDirectSlots     = 0,
                    HaveDirectSlots         = false,
                    ParentCharacterGroupIds = new[] { field.CharacterGroup.CharacterGroupId },
                    ProjectId = fieldValue.ProjectId,
                    IsRoot    = false,
                    IsSpecial = true,
                    ResponsibleMasterUserId = null,
                };
                MarkCreatedNow(fieldValue.CharacterGroup);
            }
            UpdateSpecialGroupProperties(fieldValue);
        }
Exemplo n.º 3
0
 public GameFieldDropdownValueListItemViewModel(ProjectFieldDropdownValue value)
 {
     Label          = value.Label;
     Description    = value.Description.ToHtmlString();
     IsActive       = value.IsActive;
     ProjectId      = value.ProjectId;
     ProjectFieldId = value.ProjectFieldId;
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
 }
Exemplo n.º 4
0
 public FieldPossibleValueViewModel(ProjectFieldDropdownValue value)
 {
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
     DescriptionPlainText        = value.Description.ToPlainText();
     Label                 = value.Label;
     DescriptionHtml       = value.Description.ToHtmlString();
     MasterDescriptionHtml = value.MasterDescription.ToHtmlString();
     SpecialGroupId        = value.CharacterGroup?.CharacterGroupId;
 }
        /// <summary>
        /// Save time slot options to variant
        /// </summary>
        public static void SetTimeSlotOptions(this ProjectFieldDropdownValue self, TimeSlotOptions timeSlotOptions)
        {
            if (!self.ProjectField.IsTimeSlot())
            {
                throw new Exception("That's not time slot'");
            }

            self.ProgrammaticValue = JsonConvert.SerializeObject(timeSlotOptions);
        }
Exemplo n.º 6
0
 public GameFieldDropdownValueEditViewModel(ProjectFieldDropdownValue value)
 {
     Label          = value.Label;
     Description    = value.Description.Contents;
     IsActive       = value.IsActive;
     ProjectId      = value.ProjectId;
     ProjectFieldId = value.ProjectFieldId;
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
 }
Exemplo n.º 7
0
 public GameFieldDropdownValueEditViewModel(ProjectField field, ProjectFieldDropdownValue value) : base(field)
 {
     Label       = value.Label;
     Description = value.Description.Contents;
     IsActive    = value.IsActive;
     Price       = value.Price;
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
     PlayerSelectable            = value.PlayerSelectable;
     ProgrammaticValue           = value.ProgrammaticValue;
 }
Exemplo n.º 8
0
 public GameFieldDropdownValueListItemViewModel(ProjectFieldDropdownValue value)
 {
     Label            = value.Label;
     Description      = value.Description.ToPlainText().ToString();
     IsActive         = value.IsActive;
     Price            = value.Price;
     ProjectId        = value.ProjectId;
     ProjectFieldId   = value.ProjectFieldId;
     ValueId          = value.ProjectFieldDropdownValueId;
     CharacterGroupId = value.CharacterGroup?.CharacterGroupId;
     MasterRestricted = !value.PlayerSelectable && value.ProjectField.CanPlayerEdit;
 }
        private static ProjectFieldDropdownValue GetPreviousVariant([NotNull] this ProjectField field,
                                                                    [CanBeNull] ProjectFieldDropdownValue variant)
        {
            if (variant is null)
            {
                return(field.GetOrderedValues().LastOrDefault());
            }
            var variants     = field.GetOrderedValues().ToList();
            var prevPosition = variants.IndexOf(variant) - 1;

            return(prevPosition < 0 ? null : variants[prevPosition]);
        }
 public FieldPossibleValueViewModel(ProjectFieldDropdownValue value, bool hasPrice, bool selected = false)
 {
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
     DescriptionPlainText        = value.Description.ToPlainText();
     Label                 = value.Label;
     DescriptionHtml       = value.Description.ToHtmlString();
     MasterDescriptionHtml = value.MasterDescription.ToHtmlString();
     SpecialGroupId        = value.CharacterGroup?.CharacterGroupId;
     Price                 = value.Price;
     HasPrice              = hasPrice;
     Selected              = selected;
 }
Exemplo n.º 11
0
        private void SetFieldVariantPropsFromRequest(FieldValueVariantRequestBase request,
                                                     ProjectFieldDropdownValue field)
        {
            field.Description       = new MarkdownString(request.Description);
            field.Label             = request.Label;
            field.IsActive          = true;
            field.MasterDescription = new MarkdownString(request.MasterDescription);
            field.ProgrammaticValue = request.ProgrammaticValue;
            field.Price             = request.Price;
            field.PlayerSelectable  = request.PlayerSelectable;

            CreateOrUpdateSpecialGroup(field);
        }
        /// <summary>
        /// Extract Time Slot options from programmatic value
        /// </summary>
        public static TimeSlotOptions GetTimeSlotOptions(this ProjectFieldDropdownValue self)
        {
            if (!self.ProjectField.IsTimeSlot())
            {
                throw new Exception("That's not time slot'");
            }

            if (!(self.ProgrammaticValue is null))
            {
                return(JsonConvert.DeserializeObject <TimeSlotOptions>(self.ProgrammaticValue));
            }

            return(GetDefaultTimeSlotOptions(self.ProjectField, self));
        }
Exemplo n.º 13
0
        private void CreateFieldValueVariantImpl(CreateFieldValueVariantRequest request, ProjectField field)
        {
            var fieldVariant = new ProjectFieldDropdownValue()
            {
                WasEverUsed    = false,
                ProjectId      = field.ProjectId,
                ProjectFieldId = field.ProjectFieldId,
                Project        = field.Project,
                ProjectField   = field,
            };

            SetFieldVariantPropsFromRequest(request, fieldVariant);

            field.DropdownValues.Add(fieldVariant);
        }
Exemplo n.º 14
0
        private void DeleteFieldVariantValueImpl(ProjectFieldDropdownValue field)
        {
            var characterGroup = field.CharacterGroup; // SmartDelete will nullify all depend properties

            if (SmartDelete(field))
            {
                SmartDelete(characterGroup);
            }
            else
            {
                if (characterGroup != null)
                {
                    characterGroup.IsActive = false;
                }
            }
        }
Exemplo n.º 15
0
 public GameFieldDropdownValueEditViewModel(ProjectField field, ProjectFieldDropdownValue value) : base(field)
 {
     Label       = value.Label;
     Description = value.Description.Contents;
     IsActive    = value.IsActive;
     Price       = value.Price;
     ProjectFieldDropdownValueId = value.ProjectFieldDropdownValueId;
     PlayerSelectable            = value.PlayerSelectable;
     ProgrammaticValue           = value.ProgrammaticValue;
     if (field.IsTimeSlot())
     {
         var options = value.GetTimeSlotOptions();
         TimeSlotInMinutes = options.TimeSlotInMinutes;
         TimeSlotStartTime = options.StartTime;
     }
 }
Exemplo n.º 16
0
        private void UpdateSpecialGroupProperties(ProjectFieldDropdownValue fieldValue)
        {
            var field            = fieldValue.ProjectField;
            var characterGroup   = fieldValue.CharacterGroup;
            var specialGroupName = fieldValue.GetSpecialGroupName();

            Debug.Assert(characterGroup != null, "characterGroup != null");

            if (characterGroup.IsPublic != field.IsPublic ||
                characterGroup.IsActive != fieldValue.IsActive ||
                characterGroup.Description != fieldValue.Description ||
                characterGroup.CharacterGroupName != specialGroupName)
            {
                characterGroup.IsPublic           = field.IsPublic;
                characterGroup.IsActive           = fieldValue.IsActive;
                characterGroup.Description        = fieldValue.Description;
                characterGroup.CharacterGroupName = specialGroupName;
                MarkChanged(characterGroup);
            }
        }
Exemplo n.º 17
0
        private void SetFieldVariantPropsFromRequest(FieldValueVariantRequestBase request,
                                                     ProjectFieldDropdownValue variant)
        {
            variant.Description       = new MarkdownString(request.Description);
            variant.Label             = request.Label;
            variant.IsActive          = true;
            variant.MasterDescription = new MarkdownString(request.MasterDescription);

            variant.Price            = request.Price;
            variant.PlayerSelectable = request.PlayerSelectable;
            if (variant.ProjectField.IsTimeSlot())
            {
                variant.SetTimeSlotOptions(request.TimeSlotOptions);
            }

            else
            {
                variant.ProgrammaticValue = request.ProgrammaticValue;
            }


            CreateOrUpdateSpecialGroup(variant);
        }
        private static TimeSlotOptions GetDefaultTimeSlotOptions(ProjectField field,
                                                                 ProjectFieldDropdownValue variant)
        {
            DateTimeOffset GetDefaultStartTime()
            {
                try
                {
                    var tz        = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
                    var startTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz);
                    return(startTime);
                }
                catch (TimeZoneNotFoundException)
                {
                    return(DateTimeOffset.UtcNow);
                }
            }

            var prev = field.GetPreviousVariant(variant);

            if (prev?.ProgrammaticValue is null)
            {
                return(new TimeSlotOptions()
                {
                    StartTime = GetDefaultStartTime(),
                    TimeSlotInMinutes = 50,
                });
            }

            var prevOptions = prev.GetTimeSlotOptions();

            return(new TimeSlotOptions()
            {
                TimeSlotInMinutes = prevOptions.TimeSlotInMinutes,
                StartTime = prevOptions.StartTime.Add(prevOptions.TimeSlotLength)
                            .AddMinutes(10),
            });
        }
Exemplo n.º 19
0
        public async Task CreateFieldValueVariant(int projectId, int projectCharacterFieldId, int currentUserId, string label, string description)
        {
            var field = await ProjectRepository.GetProjectField(projectId, projectCharacterFieldId);

            field.RequestMasterAccess(currentUserId, acl => acl.CanChangeFields);

            var fieldValue = new ProjectFieldDropdownValue()
            {
                Description    = new MarkdownString(description),
                Label          = label,
                IsActive       = true,
                WasEverUsed    = false,
                ProjectId      = field.ProjectId,
                ProjectFieldId = field.ProjectFieldId,
                Project        = field.Project,
                ProjectField   = field
            };

            CreateOrUpdateSpecialGroup(fieldValue);

            field.DropdownValues.Add(fieldValue);

            await UnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 20
0
        private static void CreateOrUpdateSpecialGroup(ProjectFieldDropdownValue fieldValue)
        {
            if (!fieldValue.ProjectField.HasSpecialGroup())
            {
                return;
            }
            CreateOrUpdateSpecialGroup(fieldValue.ProjectField);

            fieldValue.CharacterGroup = fieldValue.CharacterGroup ?? new CharacterGroup()
            {
                AvaiableDirectSlots     = 0,
                HaveDirectSlots         = false,
                ParentCharacterGroupIds = new [] { fieldValue.ProjectField.CharacterGroup.CharacterGroupId },
                ProjectId = fieldValue.ProjectId,
                IsRoot    = false,
                IsSpecial = true,
                ResponsibleMasterUserId = null,
            };

            fieldValue.CharacterGroup.IsPublic           = fieldValue.ProjectField.IsPublic;
            fieldValue.CharacterGroup.IsActive           = fieldValue.IsActive;
            fieldValue.CharacterGroup.Description        = fieldValue.Description;
            fieldValue.CharacterGroup.CharacterGroupName = fieldValue.GetSpecialGroupName();
        }
Exemplo n.º 21
0
 public static string GetSpecialGroupName(this ProjectFieldDropdownValue fieldValue) => $"{fieldValue.Label}";