Ejemplo n.º 1
0
        /// <summary>
        /// Adds a header to the given truth.
        /// </summary>
        /// <param name="id">The id of the truth to add a header to.</param>
        /// <param name="text">The header's text.</param>
        /// <param name="index">The index to use for footers.</param>
        /// <returns>The result.</returns>
        public ActionResult CreateHeaderFooter(int id, string text, int?index)
        {
            var truth = this.Database.Truth.Get(id);

            if (truth == null)
            {
                return(this.Fail("Unable to understand the truth."));
            }
            var light = this.Database.Light.Get(l => l.Text == text).FirstOrDefault();

            if (light == null)
            {
                light = new Light {
                    Text = text, Modified = DateTime.Now
                };
                this.Database.Save();
                LightSearch.AddOrUpdateIndex(light);
            }
            if (!truth.Love.Truths.Any(t => t.ParentId.HasValue && t.ParentId == id && t.Light != null && t.Light.Id == light.Id))
            {
                var headerFooter = new Truth {
                    Light = light, ParentId = id, Order = index ?? 0
                };
                truth.Love.Truths.Add(headerFooter);
                var hLove = Helper.FindLove(this.Database, light.Id);
                hLove.Truths.Add(new Truth {
                    ParentId = truth.Love.Id
                });
            }
            this.Database.Save();
            return(this.Success());
        }
Ejemplo n.º 2
0
 public MainWindow()
 {
     InitializeComponent();
     readResults();
     Truth.Update(truth);
     updateUiElements(30);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new new level item.
 /// </summary>
 /// <param name="truth">The truth to use as an item.</param>
 public SdwItem(Truth truth)
 {
     this.Headers = new List <SdwItem> ();
     this.Footers = new List <SdwItem> ();
     this.Styles  = new List <SdwStyle> ();
     this.Update(truth);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the truths for the current love.
        /// </summary>
        /// <param name="parameters">parameters</param>
        /// <param name="result">results</param>
        private void OnGetTruths(NameValueCollection parameters, dynamic result)
        {
            if (result.love == -1)
            {
                return;
            }
            this.LoveId = result.love;
            var url = Constants.URL_GET_BODY + this.LoveId;

            WebQueue.Instance.Get(url, this.OnGetBodies);
            url = Constants.URL_GET_STYLE + this.LoveId;
            WebQueue.Instance.Get(url, this.OnGetStyles);
            url = Constants.URL_GET_ALIAS + this.LoveId;
            WebQueue.Instance.Get(url, this.OnGetAlias);
            foreach (var t in result.truths)
            {
                var lights = new List <Light> ();
                foreach (var light in t.Value.l)
                {
                    lights.Add(new Light {
                        Id = light.id, Text = light.text
                    });
                }
                var love = new Love {
                    Id    = t.Value.id,
                    Light = lights.Last()
                };
                for (var a = 0; a < lights.Count - 1; a++)
                {
                    love.Peace.Add(lights [a]);
                }
                var truth = new Truth(this, Convert.ToInt32(t.Value.tid))
                {
                    Order      = t.Value.order,
                    Love       = love,
                    IsModified = false
                };
                if (t.Value.a != null)
                {
                    truth.Alias = Convert.ToInt32(t.Value.a);
                }
                if (t.Value.b != null)
                {
                    foreach (var body in t.Value.b)
                    {
                        truth.Bodies.Add(new Body(truth, Convert.ToInt32(t.Value.id))
                        {
                            Id       = body.id,
                            Text     = body.text,
                            Position = body.position
                        });
                    }
                }
                this.Truth.Add(truth);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Updates the level item for the given truth.
 /// </summary>
 /// <param name="truth">Truth to use.</param>
 public void Update(Truth truth)
 {
     this.TruthId  = truth.Id;
     this.Order    = truth.Order;
     this.Number   = truth.Number;
     this.ParentId = truth.ParentId;
     if (truth.Light != null)
     {
         this.Id   = truth.Light.Id;
         this.Text = truth.Light.Text;
         this.Styles.AddRange(truth.Styles.Select(s => new SdwStyle(s)));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Edits the love of the given truth.
        /// </summary>
        /// <param name="truth">Truth to edit.</param>
        public void EditTruth(Truth truth)
        {
            var love = new LoveViewModel {
                IsUpdating = true, IsExpanded = true
            };

            foreach (var light in truth.Love.Peace)
            {
                love.Light.Add(new Light(light));
            }
            love.IsUpdating = false;
            love.Light.Add(truth.Love.Light);
            this.Love.Insert(0, love);
            this.OnLoveAdded();
        }
Ejemplo n.º 7
0
 public ICommandResult Add(TruthAddCommand command)
 {
     try
     {
         var truth = new Truth {
             Description = command.Description, Type = command.Type
         };
         _truthRepository.Create(truth);
         var commandResult = new CommandResult("Verdade adicionada com sucesso!", truth, false);
         return(commandResult);
     }
     catch (Exception ex)
     {
         var commandResult = new CommandResult($"{ex.InnerException.Message}", null, true);
         return(commandResult);
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Formats the text to format with the selected regular expression.
        /// </summary>
        private void Format()
        {
            var number = this.StartNumber;

            if (!this.AppendFormattedText)
            {
                for (var i = this.Truth.Count - 1; i >= 0; i--)
                {
                    if (this.Truth[i].Id <= 0)
                    {
                        this.Truth.RemoveAt(i);
                    }
                }
            }
            var matches = Regex.Matches(this.TextToFormat, this.CurrentRegex, RegexOptions.IgnoreCase);

            foreach (Match match in matches)
            {
                var numberGroup = match.Groups ["n"];
                var headerGroup = match.Groups ["h"];
                var footerGroup = match.Groups ["f"];
                if (numberGroup.Success)
                {
                    number = Convert.ToInt32(numberGroup.Value);
                }
                var text  = match.Groups ["t"].Value.Trim();
                var truth = new Truth(this)
                {
                    IsNew = true,
                    Love  = new Love {
                        Light = new Light {
                            Text = text
                        }
                    }
                };
                if (numberGroup.Success || number.HasValue)
                {
                    truth.Bodies.Add(new Body(truth)
                    {
                        BodyType = BodyType.Left,
                        Text     = number.ToString()
                    });
                }
                if (headerGroup.Success)
                {
                    truth.Bodies.Add(new Body(truth)
                    {
                        BodyType = BodyType.Header,
                        Text     = headerGroup.Value
                    });
                }
                if (footerGroup.Success)
                {
                    truth.Bodies.Add(new Body(truth)
                    {
                        BodyType = BodyType.Footer,
                        Text     = footerGroup.Value
                    });
                }
                foreach (var light in this.Light)
                {
                    truth.Love.Peace.Add(new Light(light));
                }
                this.Truth.Add(truth);
                if (!numberGroup.Success && number.HasValue)
                {
                    number++;
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Removes the given truth from the list.
 /// </summary>
 /// <param name="truth">The truth to remove.</param>
 internal void RemoveTruth(Truth truth)
 {
     this.Truth.Remove(truth);
 }
Ejemplo n.º 10
0
 public override string ToString() => Truth.ToString().ToLower();