public Command GetCommand(ReportLevel reportLevel, string dateTime, string message)
        {
            Command cmd = null;

            switch (reportLevel)
            {
            case ReportLevel.Info:
                cmd = new InfoCommand(dateTime, reportLevel, message);
                break;

            case ReportLevel.Warning:
                cmd = new WarningCommand(dateTime, reportLevel, message);
                break;

            case ReportLevel.Error:
                cmd = new ErrorCommand(dateTime, reportLevel, message);
                break;

            case ReportLevel.Critical:
                cmd = new CriticalCommand(dateTime, reportLevel, message);
                break;

            case ReportLevel.Fatal:
                cmd = new FatalCommand(dateTime, reportLevel, message);
                break;
            }

            return(cmd);
        }
示例#2
0
        public ActionResult GiveWarning([FromBody] WarningCommand model)
        {
            if (_context.Users.Find(model.UserId) == null || _context.Users.Find(model.AdminId) == null)
            {
                return(NotFound("Could not find user with this id"));
            }

            var warning = new Warning();

            warning.Reason      = model.Reason;
            warning.Explanation = model.Explanation;
            warning.DateTime    = DateTime.Now.AddHours(2);
            warning.UserId      = model.UserId;
            warning.AdminId     = model.AdminId;

            try
            {
                _context.Warnings.Add(warning);
                _context.SaveChanges();
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest("An error occured while trying to add warning."));
            }
        }