public async Task <IActionResult> Edit(int id, [Bind("IID,Day_opened,Day_closed,Description,Resolution,TenantTID")] Infractions infractions)
        {
            if (id != infractions.IID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(infractions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InfractionsExists(infractions.IID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Tenants", new { id = infractions.TenantTID }));
            }
            ViewData["TenantTID"] = new SelectList(_context.Tenant, "TID", "Last_name", infractions.TenantTID);
            return(View(infractions));
        }
示例#2
0
        /// <returns>The old reason</returns>
        public string ChangeInfractionReason(uint id, string newReason)
        {
            var infraction = Infractions.Find(x => x.Id == id);
            var oldReason  = infraction.Reason;

            infraction.Reason = newReason;
            return(oldReason);
        }
示例#3
0
        /// <returns>The warning made.</returns>
        public Infraction AddInfractionToGuild(ulong userId, ulong moderatorId, InfractionType type, DateTime?endsAt, string reason)
        {
            var infraction = new Infraction(++LastUsedModerationId, userId, moderatorId, type, endsAt, reason);

            Infractions.Add(infraction);

            return(infraction);
        }
        public async Task <IActionResult> Create([Bind("IID,Day_opened,Day_closed,Description,Resolution,TenantTID")] Infractions infractions)
        {
            if (ModelState.IsValid)
            {
                _context.Add(infractions);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Tenants", new { id = infractions.TenantTID }));
            }
            ViewData["TenantTID"] = new SelectList(_context.Tenant, "TID", "Last_name", infractions.TenantTID);
            return(View(infractions));
        }
示例#5
0
        /// <returns>The old warning</returns>
        public Infraction RemoveWarningById(uint id)
        {
            var infraction = Infractions.Find(x => x.Id == id);

            if (infraction.Type != InfractionType.Warning)
            {
                throw new Exception($"Case {id} is not a warning!");
            }

            Infractions.Remove(infraction);
            return(infraction);
        }
示例#6
0
        public TimeSpan UpdateInfractionDuration(uint id, TimeSpan newTime)
        {
            var infraction = Infractions.Find(x => x.Id == id);

            if (infraction.Type != InfractionType.Ban && infraction.Type != InfractionType.Mute)
            {
                throw new Exception($"You can only change the duration on a ban or a mute.");
            }
            else if (infraction.FinishesAt < DateTime.UtcNow)
            {
                throw new Exception($"You cannot edit a mute/ban that has already finished.");
            }

            var oldTime = (infraction.FinishesAt - DateTime.UtcNow).Value;

            infraction.FinishesAt = DateTime.UtcNow.Add(newTime);
            return(oldTime);
        }
示例#7
0
        private List <GroupedInfractions> GetGroupedInfractions()
        {
            List <GroupedInfractions> groupedInfractions = new List <GroupedInfractions>();

            if (Infractions == null || Infractions.Count == 0)
            {
                return(groupedInfractions);
            }

            foreach (var groupedItem in Infractions.GroupBy(x => x.InfractionID))
            {
                groupedInfractions.Add(new GroupedInfractions()
                {
                    Infraction = groupedItem.First(),
                    Occurances = groupedItem.Count(),
                    Deduction  = groupedItem.Sum(x => x.Deduction)
                });
            }

            TotalDeduction = groupedInfractions.Sum(x => x.Deduction);

            return(groupedInfractions);
        }
示例#8
0
        /// <summary>
        /// The Get Infractions method queries the database for all infractions that have not been revoked
        /// based on the warned user's snowflake ID.
        /// </summary>
        /// <param name="UserID">The ID of the user you wish to query the infractions of.</param>
        /// <returns>An array of infraction objects that the user has.</returns>

        public Infraction[] GetInfractions(ulong UserID) =>
        Infractions.AsQueryable()
        .Where(Warning => Warning.User == UserID && Warning.EntryType != EntryType.Revoke)
        .ToArray();