Beispiel #1
0
        public IActionResult Audit(string id)
        {
            var r = new AddEntryResultModel();

            r.Name = id;

            try
            {
                r.Problems = _auditor.PerformEntryAudit(id);
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.ToString());
                r.Problems.Add("Baza danych się popsuła");
            }

            return(Json(r));
        }
Beispiel #2
0
        public async Task <IActionResult> Add([FromForm] AddEntryModel model)
        {
            var r = new AddEntryResultModel();

            r.Problems = model.Validate();
            r.Name     = model.Name;
            r.Url      = Url.Action("Entry", "Home", new { name = model.Name });

            if (r.Problems.Count == 0)
            {
                try
                {
                    var e = new Entry();
                    e.Name            = model.Name;
                    e.Meanings        = model.Meanings;
                    e.EnglishMeanings = model.EnglishMeanings;
                    e.SeeAlso         = model.SeeAlso;
                    e.Examples        = model.Examples;
                    e.TimeAdded       = DateTimeOffset.UtcNow;
                    e.FromInternet    = true;
                    e.IPAddress       = null;

                    // TODO: Clean up this hack
                    r.Problems = _auditor
                                 .PerformEntryAudit(e)
                                 .Where(txt => !txt.Contains("link"))
                                 .ToList();

                    if (r.Problems.Count == 0)
                    {
                        var user = await this.GetCurrentUserAsync();

                        e.ApprovedBy = user?.UserName;

                        _repo.AddEntry(e);
                    }
                }
                catch (System.Exception)
                {
                    r.Problems.Add("Baza danych się popsuła");
                }
            }

            return(Json(r));
        }