//New schedule public async Task <int> Create(ScheduleContainer schedule) { if (schedule == null) { throw new ArgumentNullException(); } var now = DateTime.Now; if (!AllowCreate(now)) { throw new BussinessException("Not accepting new schedule at the moment."); } await ThrowIfCheckFail(schedule); var posSchedule = schedule.ToPosSchedule(); //User submited schedule posSchedule.AutoFill = false; posSchedule.SubmitTime = now; await DbContext.PosSchedule.AddAsync(posSchedule); await DbContext.SaveChangesAsync(); return(posSchedule.PosScheduleId); }
public async Task <IActionResult> Create([FromBody] ScheduleContainer schedule) { if (!ModelState.IsValid) { return(BadRequest()); } try { var id = await _service.Create(schedule); return(Ok(id)); } catch (BussinessException ex) //Fail bussiness check { _logger.LogDebug(ex.Message); return(BadRequest(ex.Message)); } catch (DbUpdateException ex) { Helper.Utility.LogException(ex, _logger); return(BadRequest("System error.")); } catch (SqlException ex) { Helper.Utility.LogException(ex, _logger); return(BadRequest("System error.")); } }
///<inheritdoc/> public void UpdateSchedule(ScheduleContainer scheduleContainer) { if (scheduleContainer is null) { throw new Exception("Schedule container hasn't set"); } _scheduleContext.ScheduleContainers.Update(scheduleContainer); _scheduleContext.SaveChanges(); }
public static void put_watcher_sample(ElasticClient client) { // action var action = new LoggingAction("mylog") { Text = "some node is down", Level = LogLevel.Info }; ConditionContainer condition = new AlwaysCondition(); var my_http = new HttpInputRequest { Host = "localhost", Port = 9200, Path = "_cat/nodes", Method = HttpInputMethod.Get }; var input = new HttpInput { Request = my_http }; var hourly = new HourlySchedule(); int[] intNumbers = new int[] { 30 }; hourly.Minute = intNumbers; var trigger = new ScheduleContainer { Hourly = hourly }; var id = "status-check"; PutWatchRequest watchRequest = new PutWatchRequest(id) { Actions = action, Condition = condition, Input = input, Trigger = trigger }; PutWatchResponse response = client.Watcher.Put(watchRequest); Console.WriteLine("hello"); }
/// <summary> /// Check if schedule sastisfies bussines logic /// </summary> /// <param name="scheduleContainer"></param> /// <returns></returns> private async Task ThrowIfCheckFail(ScheduleContainer scheduleContainer) { var userId = UserId; if (scheduleContainer == null) { throw new ArgumentNullException($"Param: {nameof(scheduleContainer)} is null."); } var emptyDefine = scheduleContainer.Schedules.FirstOrDefault(s => s.Shift == null || s.User == null); if (emptyDefine != null) { throw new BussinessException($"Some shift details missing shift/user definition"); } //Check format valid if (!scheduleContainer.CheckBasicFormat(out string formatReason)) { throw new BussinessException(formatReason); } //Every day of month must have shifts defined var missing = scheduleContainer.DaysInMonthRange.Select(d => d.Day).Except(scheduleContainer.Schedules.Select(s => s.Day)); if (missing.Any()) { throw new BussinessException($"Missing shift for days: {string.Concat(missing.Select(s => s.ToString("dd") + " "))}"); } //Check logic/bussiness valid //Find any dupicate of same ShiftDate-ShiftId-UserId var dupFound = from s in scheduleContainer.Schedules group s by new { s.Day, s.Shift.ShiftId, s.User.UserId } into g select g; int dupCount = dupFound.Count(g => g.Count() > 1); if (dupCount > 0) { throw new BussinessException($"Duplicate of exact same detail count: {dupCount}"); } //Check if this POS is manage by this user if (!DbContext.Pos.Any(p => p.PosId == scheduleContainer.TargetPos)) { throw new BussinessException($"Target pos: {scheduleContainer.TargetPos} is not managed by user id: {userId}"); } //Get all shift of POS var shiftsOfPos = await DbContext.PosShift .Where(ps => ps.PosId == scheduleContainer.TargetPos) .Select(ps => ps.Shift) .AsNoTracking() .ToListAsync(); if (!shiftsOfPos.Any()) { throw new BussinessException($"Cant find any shifts of target pos: {scheduleContainer.TargetPos}"); } var groupByDate = scheduleContainer.Schedules.GroupBy(s => s.Day); //Every day must have number shift defined equals to number of shift the POS has //For ex: POS123 have 4 shift, every day of schedule must have 4 shift schedule defined //Also if detail contains ShiftId that are not defined in PosShift of the POS then -> not valid //All shift ids of POS must have 1 match //ShiftId of POS except shiftid of day if any then not all are defined if (groupByDate.Any(g => shiftsOfPos .Select(shiftId2 => shiftId2.ShiftId) .Except(g.Select(s => s.Shift.ShiftId)) .Any())) { throw new BussinessException($"Some shift ids are not valid or POS does not have this shift"); } //Check all user id of shift detail are managed by current user //Get all user under this user management var managedUserIds = await DbContext.AppUser .Where(u => u.ManagerId == userId) .Select(u => u.UserId) .ToListAsync(); if (!managedUserIds.Any()) { throw new BussinessException($"UserId: {userId} have no users under management"); } //Group by all user ids of schedule var groupByUserId = scheduleContainer.Schedules .GroupBy(s => s.User.UserId) .Select(u => u.First().User.UserId); var notUnderManaged = groupByUserId.Except(managedUserIds); if (notUnderManaged.Any()) { throw new BussinessException($"User ids: {string.Concat(notUnderManaged.Select(u => u + " "))} are not managed by: {userId}"); } //Check if this specific schedule Month/Year has been defined if (DbContext.PosSchedule.Any( s => s.Pos.PosId == scheduleContainer.TargetPos && s.MonthYear.Month == scheduleContainer.MonthYear.Month && s.MonthYear.Year == scheduleContainer.MonthYear.Year)) { throw new BussinessException($"Schedule: {scheduleContainer.MonthYear.ToString("MM/yyyy")} of POS: {scheduleContainer.TargetPos} has already been defined"); } //Clean }
private void matchChanged(ValueChangedEvent <TournamentMatch> match) { var upcoming = ladder.Matches.Where(p => !p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4); var conditionals = ladder .Matches.Where(p => !p.Completed.Value && (p.Team1.Value == null || p.Team2.Value == null) && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) .SelectMany(m => m.ConditionalMatches.Where(cp => m.Acronyms.TrueForAll(a => cp.Acronyms.Contains(a)))); upcoming = upcoming.Concat(conditionals); upcoming = upcoming.OrderBy(p => p.Date.Value).Take(8); ScheduleContainer comingUpNext; mainContainer.Child = new FillFlowContainer { RelativeSizeAxes = Axes.Both, Direction = FillDirection.Vertical, Children = new Drawable[] { new Container { RelativeSizeAxes = Axes.Both, Height = 0.74f, Child = new FillFlowContainer { RelativeSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, Children = new Drawable[] { new ScheduleContainer("recent matches") { RelativeSizeAxes = Axes.Both, Width = 0.4f, ChildrenEnumerable = ladder.Matches .Where(p => p.Completed.Value && p.Team1.Value != null && p.Team2.Value != null && Math.Abs(p.Date.Value.DayOfYear - DateTimeOffset.UtcNow.DayOfYear) < 4) .OrderByDescending(p => p.Date.Value) .Take(8) .Select(p => new ScheduleMatch(p)) }, new ScheduleContainer("upcoming matches") { RelativeSizeAxes = Axes.Both, Width = 0.6f, ChildrenEnumerable = upcoming.Select(p => new ScheduleMatch(p)) }, } } }, comingUpNext = new ScheduleContainer("coming up next") { RelativeSizeAxes = Axes.Both, Height = 0.25f, } } }; if (match.NewValue != null) { comingUpNext.Child = new FillFlowContainer { AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, Spacing = new Vector2(30), Children = new Drawable[] { new ScheduleMatch(match.NewValue, false) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, }, new TournamentSpriteTextWithBackground(match.NewValue.Round.Value?.Name.Value) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Scale = new Vector2(0.5f) }, new TournamentSpriteText { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Text = match.NewValue.Team1.Value?.FullName + " vs " + match.NewValue.Team2.Value?.FullName, Font = OsuFont.Torus.With(size: 24, weight: FontWeight.SemiBold) }, new FillFlowContainer { AutoSizeAxes = Axes.Both, Direction = FillDirection.Horizontal, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Children = new Drawable[] { new ScheduleMatchDate(match.NewValue.Date.Value) { Font = OsuFont.Torus.With(size: 24, weight: FontWeight.Regular) } } }, } }; } }