public void UpdateViolator()
        {
            var violator = new Violator();

            Console.WriteLine("Update violator");

            try
            {
                Console.WriteLine("Indicate id: ");
                violator.Id = int.Parse(Console.ReadLine());
                Console.WriteLine("Reinspection date (yy-mm-dd): ");
                violator.ReinspectionDate = DateTimeOffset.Parse(Console.ReadLine());

                _violatorService.UpdateAsync(violator).GetAwaiter().GetResult();
                Console.Write("Violator updated succesfully ");
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (NotFoundException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (DateException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void CreateViolator()
        {
            var violator = new Violator();

            try
            {
                Console.WriteLine("Create violator");
                Console.WriteLine("Driver id: ");
                violator.DriverId = int.Parse(Console.ReadLine());
                Console.WriteLine("Inspector id: ");
                violator.InspectorId = int.Parse(Console.ReadLine());
                Console.WriteLine("Violation id: ");
                violator.ViolationId = int.Parse(Console.ReadLine());
                Console.WriteLine("Reinspection date (yy-mm-dd): ");
                violator.ReinspectionDate = DateTimeOffset.Parse(Console.ReadLine());

                _violatorService.CreateAsync(violator).GetAwaiter().GetResult();
                Console.Write("Violator created succesfully ");
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (DateException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #3
0
 private Violator IncreasePoint(ICommandContext context, Violator violator)
 {
     violator.LatestViolation = DateTime.UtcNow;
     violator.Points++;
     _logger.LogInformation(new EventId(200), $"{context.User}'s Points {violator.Points - 1} => {violator.Points}");
     return(violator);
 }
Example #4
0
        public ActionResult Create(Violator violator)
        {
            if (ModelState.IsValid)
            {
                var dao = new ViolatorDao();

                //lấy id trong session đăng nhập của quản trị lưu vào phiên tạo mới user
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                violator.CreatedBy   = session.UserName;
                violator.CreatedDate = DateTime.Now;

                long id = dao.Insert(violator);
                if (id > 0)
                {
                    SetAlert("Thêm chấm công nhân viên thành công", "success");
                    return(RedirectToAction("Index", "Violator"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm chấm nhân viên công không thành công");
                }
            }
            SetViewBag();
            SetTypeBag();
            SetAlert("Error", "error");
            return(RedirectToAction("Index", "Violator"));
        }
Example #5
0
        public Violator DecreasePoints(ICommandContext context, Violator violator)
        {
            var decPoints = 0;
            var time      = violator.LatestViolation;

            while (DateTime.UtcNow > time)
            {
                if (DateTime.UtcNow > time.AddHours(Convert.ToDouble(_config["PointDecreaseHours"])))
                {
                    if (decPoints == violator.Points)
                    {
                        break;
                    }

                    time = time.AddHours(Convert.ToDouble(_config["PointDecreaseHours"]));
                    decPoints++;
                    violator.Points          = violator.Points - decPoints <= 0 ? 0 : violator.Points - decPoints;
                    violator.LatestViolation = time;
                }
                else
                {
                    break;
                }
            }
            _logger.LogInformation(new EventId(200), $"Decreased {context.User}'s points({violator.Points + decPoints}) by {decPoints} for a total of {violator.Points}");
            return(violator);
        }
Example #6
0
        private static async Task <Violator> IncreasePoint(ICommandContext context, Violator violator)
        {
            violator.LatestViolation = DateTime.UtcNow;
            violator.Points++;
            Logger.Info($"{context.User}'s Points {violator.Points - 1} => {violator.Points}");
            await violator.SaveAsync();

            return(violator);
        }
Example #7
0
        public long Update(Violator entity, string username)
        {
            var violator = db.Violators.Find(entity.ID);

            violator.Employee_ID = entity.Employee_ID;
            violator.Type_ID     = entity.Type_ID;
            violator.Loan        = entity.Loan;
            violator.Description = entity.Description;

            //Ngày chỉnh sửa = Now
            violator.ModifiedBy   = username;
            violator.ModifiedDate = DateTime.Now;
            db.SaveChanges();
            return(entity.ID);
        }
Example #8
0
        private async void export()
        {
            int i = 0;

            dt.Rows.Clear();
            FirebaseResponse response = await client.GetTaskAsync("Counter/number");

            Counter obj1 = response.ResultAs <Counter>();
            int     cnt  = Convert.ToInt32(obj1.cnt);

            while (true)
            {
                if (i == cnt)
                {
                    break;
                }
                i++;
                try
                {
                    FirebaseResponse response1 = await client.GetTaskAsync("Violator/" + i);

                    Violator obj2 = response1.ResultAs <Violator>();

                    DataRow row = dt.NewRow();
                    row["TVBNo"]            = obj2.TVBNo;
                    row["Type"]             = obj2.type;
                    row["Date"]             = obj2.date;
                    row["Time"]             = obj2.time;
                    row["To"]               = obj2.to;
                    row["License No"]       = obj2.licenseNo;
                    row["Address"]          = obj2.address1;
                    row["Vehicle Plate No"] = obj2.plateNo;
                    row["Vehicle Make"]     = obj2.make;
                    row["Vehicle Color"]    = obj2.color;
                    row["Vehicle Owner"]    = obj2.owner;
                    row["Owner Address"]    = obj2.address1;
                    row["Violation"]        = obj2.violation;
                    row["Fine"]             = obj2.Price;
                    row["Location"]         = obj2.Location;
                    row["Enforcer"]         = obj2.Enforcer;
                    dt.Rows.Add(row);
                }
                catch { }
            }
        }
Example #9
0
        public ActionResult Edit(Violator violator)
        {
            if (ModelState.IsValid)
            {
                var dao     = new ViolatorDao();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];

                long id = dao.Update(violator, session.UserName);
                if (id > 0)
                {
                    SetAlert("Sửa thông tin nhân viên thành công", "success");
                    return(RedirectToAction("Index", "Violator"));
                }
                else
                {
                    SetAlert("Tài khoản hoặc mã nhân viên đã tồn tại!", "error");
                    return(RedirectToAction("Index", "Violator"));
                }
            }
            SetTypeBag();
            SetViewBag();
            SetAlert("Sửa thông tin nhân viên thất bại", "error");
            return(RedirectToAction("Index", "Violator"));
        }
Example #10
0
        private async Task ExecutePenalty(ICommandContext context, Violator violator, BlockType blockType)
        {
            var penalties = (await _unit.Penalties.GetOrCreateAllAsync(context.Guild)).ToList();
            var stats     = await _unit.Statistics.GetOrCreateAsync(context.Guild);

            stats.Blocks++;

            foreach (var penalty in penalties.OrderBy(p => p.RequiredPoints))
            {
                if (violator.Points != penalty.RequiredPoints)
                {
                    continue;
                }
                var message = penalty.Message ?? GetDefaultMessage(penalty.PenaltyType);

                string logresponse;
                switch (penalty.PenaltyType)
                {
                case PenaltyType.Nothing:
                    await MessagePenalty.SendWithEmoteAsync(_factory, context, message, GetTrigger(blockType),
                                                            autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Nothing {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:NoAds:330796107540201472>"), logresponse);

                    break;

                case PenaltyType.Warn:
                    await MessagePenalty.SendWithEmoteAsync(_factory, context, message, GetTrigger(blockType),
                                                            Emote.Parse("<:Warn:330799457371160579>"), penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Warn {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Warn:330799457371160579>"), logresponse);

                    stats.Warns++;
                    break;

                case PenaltyType.Kick:
                    await KickPenalty.KickAsync(_factory, context, message, GetTrigger(blockType),
                                                autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Kick {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Kick:330793607919566852>"), logresponse);

                    stats.Kicks++;
                    break;

                case PenaltyType.Ban:
                    await BanPenalty.BanAsync(_factory, context, message, GetTrigger(blockType),
                                              autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Ban {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Ban:330793436309487626>"), logresponse);

                    stats.Bans++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (violator.Points >= penalties.Max(p => p.RequiredPoints))
            {
                _unit.Violators.Remove(violator);
                _logger.LogInformation(new EventId(200), $"{context.User} reached the last penalty in {context.Guild}, dropping from Database.");
            }
        }
Example #11
0
        private static async Task ExecutePenalty(ICommandContext context, Violator violator, BlockType blockType)
        {
            var penalties = await _mongo.GetCollection <Penalty>(_client).GetPenaltiesAsync(violator.GuildId);

            var collection = _mongo.GetCollection <Stats>(_client);
            var stats      = await collection.GetGuildStatsAsync(context.Guild);

            stats.Blocks++;

            foreach (var penalty in penalties.OrderBy(p => p.RequiredPoints))
            {
                if (violator.Points != penalty.RequiredPoints)
                {
                    continue;
                }
                var message = penalty.Message ?? GetDefaultMessage(penalty.PenaltyType);


                string logresponse;
                switch (penalty.PenaltyType)
                {
                case PenaltyType.Nothing:
                    await MessagePenalty.SendWithEmoteAsync(context, message, GetTrigger(blockType),
                                                            autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Nothing {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:NoAds:330796107540201472>"), logresponse);

                    break;

                case PenaltyType.Warn:
                    await MessagePenalty.SendWithEmoteAsync(context, message, GetTrigger(blockType),
                                                            Emote.Parse("<:Warn:330799457371160579>"), penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Warn {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Warn:330799457371160579>"), logresponse);

                    stats.Warns++;
                    break;

                case PenaltyType.Kick:
                    await KickPenalty.KickAsync(context, message, GetTrigger(blockType),
                                                autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Kick {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Kick:330793607919566852>"), logresponse);

                    stats.Kicks++;
                    break;

                case PenaltyType.Ban:
                    await BanPenalty.BanAsync(context, message, GetTrigger(blockType),
                                              autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Ban {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Ban:330793436309487626>"), logresponse);

                    stats.Bans++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            await stats.SaveAsync();

            if (violator.Points >= penalties.Max(p => p.RequiredPoints))
            {
                await violator.DeleteAsync();

                Logger.Info($"{context.User} reached the last penalty in {context.Guild}, dropping from Database.");
            }
        }
Example #12
0
        public static async Task <Violator> TryDecreasePoints(ICommandContext context, Violator violator)
        {
            var decPoints = 0;
            var time      = violator.LatestViolation;

            while (DateTime.UtcNow > time)
            {
                if (DateTime.UtcNow > time.AddHours(_config.PointDecreaseHours))
                {
                    if (decPoints == violator.Points)
                    {
                        break;
                    }

                    time = time.AddHours(_config.PointDecreaseHours);
                    decPoints++;
                    violator.Points          = violator.Points - decPoints <= 0 ? 0 : violator.Points - decPoints;
                    violator.LatestViolation = time;
                }
                else
                {
                    break;
                }
            }
            Logger.Info($"Decreased {context.User}'s points({violator.Points + decPoints}) by {decPoints} for a total of {violator.Points}");
            await violator.SaveAsync();

            return(violator);
        }
Example #13
0
 public long Insert(Violator entity)
 {
     db.Violators.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }