public IActionResult AjaxCreateSchedule([FromBody] CreateSchedule createSchedule)
 {
     if (ModelState.IsValid)
     {
         var startTime              = TimeSpan.Parse(createSchedule.StartTime);
         var endTime                = TimeSpan.Parse(createSchedule.EndTime);
         var conversationType       = _context.ConversationTypes.First(ct => ct.Id == createSchedule.ConversationType);
         var user                   = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         List <CreateSchedule> list = new List <CreateSchedule>();
         while (true)
         {
             if (startTime.Equals(endTime) || startTime.Ticks > endTime.Ticks)
             {
                 break;
             }
             CreateSchedule schedule = new CreateSchedule();
             schedule.Date      = createSchedule.Date;
             schedule.StartTime = startTime.ToString();
             startTime          = startTime.Add(new TimeSpan(0, conversationType.ConversationDuration, 0));
             schedule.EndTime   = startTime.ToString();
             list.Add(schedule);
         }
         list[0].ConversationType = conversationType.Id;
         return(PartialView("PartialAjaxGenerateSchedule", list));
     }
     else
     {
         return(Content(createSchedule.Error));
     }
 }
Ejemplo n.º 2
0
        public ActionResult CreateMatches(string DeleteIT)
        {
            var numOfWeeks = db.WednesdaySchedules.Count();
            var numofTeams = db.WednesdayTeams.Count();

            db.WednesdayMatches.RemoveRange(db.WednesdayMatches);
            db.SaveChanges();
            var cs = new CreateSchedule();

            var matches = numofTeams % 2 == 0 ? cs.NoByes(numOfWeeks, numofTeams) : cs.Byes(numOfWeeks, numofTeams);

            foreach (var match in matches)
            {
                db.WednesdayMatches.Add(new WednesdayMatch()
                {
                    id         = 0,
                    GameDate   = match.Week + 1,
                    Rink       = match.Rink == -1 ? -1 : match.Rink + 1,
                    Team1      = match.Team1 + 1,
                    Team2      = match.Team2 + 1,
                    Team1Score = 0,
                    Team2Score = 0
                });
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
            }

            return(RedirectToAction("index", new { ScheduleID = 1 }));
        }
Ejemplo n.º 3
0
        //Create new schedule at school
        public ActionResult CreateSchool(CreateSchedule model)
        {
            View();
            var times   = GetAllTimes();
            var courses = GetAllCourses();
            var cList   = GetCourses(courses);
            var tutors  = GetTutorByLocation(ListOfLocations.School);
            var tList   = GetLocationsTutors(tutors);

            model.AvailableDays    = TimesSelectListItems(times);
            model.AvailableTutors  = LocationTutorListItems(tList);
            model.AvailableCourses = CourseListItems(cList);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateScheduleService();

            if (service.CreateSchedule(model))
            {
                TempData["SaveResult"] = "A new schedule was added.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "A schedule could not be added.");
            return(View(model));
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //GetTypes(typeof(IHandleCommand<>));

            var builder = new ContainerBuilder();

            // 1) REgister through the CommandModule
            //builder.RegisterAssemblyModules(typeof(CommandModule).Assembly);
            builder.RegisterModule(new AutofacCommandModule(typeof(IHandleCommand <>), AppDomain.CurrentDomain.GetAssemblies()));
            builder.RegisterType <ScheduleRepository>().As <IScheduleRepository>();
            builder.RegisterType <ApplicationHost>();
            builder.RegisterType <CommandDispatcher>()
            .WithParameter(new TypedParameter(typeof(Type), typeof(IHandleCommand <>)))
            .As <ICommandDispatcher>();
            //    .. or
            //// 2) Register manually
            //// a) loop through assembly
            ////      tba
            //// b)
            //builder.RegisterType<AutofacHandlerResolver>()
            //           .As<IHandlerResolver>();
            //// c)
            //builder.RegisterType<CommandDispatcher>().As<ICommandDispatcher>();

            Container = builder.Build();

            foreach (var item in Container.ComponentRegistry.Registrations)
            {
                string message = item.Activator.ToString() + "\n\tServices:";
                foreach (var service in item.Services)
                {
                    message += "\n\t\t" + service.Description;
                }
                message += "\n\tMetaData";
                foreach (var md in item.Metadata)
                {
                    message += "\n\t\t" + md.Key + ":" + md.Value;
                }
                Console.WriteLine(message);
                Console.WriteLine("---------------------");
                //Console.WriteLine(item);
            }

            using (var scope = Container.BeginLifetimeScope())
            {
                var dispatcher = scope.Resolve <ApplicationHost>();// scope.Resolve<ICommandDispatcher>();
                Console.WriteLine(dispatcher);

                var command = new CreateSchedule();
                dispatcher.Process(command);
                //dispatcher.SendCommand(command);
            }
        }
Ejemplo n.º 5
0
        public void Export_schedule()
        {
            var fixture = new CreateSchedule {
                Schedules = new[] { new TimeSpan(14, 0, 0) }
            };

            Fixture(fixture);
            Run(new UpdateCommand());

            var schedules = localSession.Query <Schedule>().ToArray();

            Assert.AreEqual(1, schedules.Length);
            Assert.AreEqual(new TimeSpan(14, 0, 0), schedules[0].UpdateAt);
        }
Ejemplo n.º 6
0
 public IHttpActionResult Create(Guid hospitalId, CreateSchedule model)
 {
     using (var dbContext = new AppContext())
     {
         var schedule = new Schedule
         {
             CreatedAt  = DateTime.Now,
             Date       = model.Date,
             HospitalId = hospitalId,
             Id         = Guid.NewGuid(),
             UserId     = Util.GetUserId()
         };
         dbContext.Schedule.Add(schedule);
         return(Created("/me/schedules", schedule));
     }
 }
Ejemplo n.º 7
0
        //Create a new schedule - separated by location in Controller
        public bool CreateSchedule(CreateSchedule model)
        {
            int    position       = model.ScheduleTutorID.IndexOf("-");
            int    tutorNum       = Int32.Parse(model.ScheduleTutorID.Substring(0, position));
            int    coursePosition = model.ScheduleCourseID.IndexOf("-");
            int    courseNum      = Int32.Parse(model.ScheduleCourseID.Substring(0, coursePosition));
            int    DaySelPos      = model.ScheduleDay.IndexOf(":");
            string DaySel         = model.ScheduleDay.Substring(DaySelPos - 1);
            int    hour           = 3;

            if (DaySel == "3:00")
            {
                hour = 15;
            }
            ;
            if (DaySel == "5:00")
            {
                hour = 17;
            }
            ;
            if (DaySel == "1:00")
            {
                hour = 13;
            }
            ;

            DateTime sch = new DateTime(model.ScheduleDate.Year, model.ScheduleDate.Month, model.ScheduleDate.Day, hour, 0, 0);

            model.ScheduleRate = 20;
            var entity =
                new Schedule()
            {
                StudentId = model.ScheduleStudentID,
                TutorId   = tutorNum,
                CourseId  = courseNum,
                Time      = sch,
                Rate      = model.ScheduleRate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Schedules.Add(entity);
                return(ctx.SaveChanges() > 0);
            }
        }
Ejemplo n.º 8
0
        public JsonResult GatherScheduleData(CreateSchedule schdl)
        {
            var status = false;


            //var DateStart = (schdl.Dates.ToString().Split('-')[0]);
            //var changeDS = DateTime.Parse(DateStart.ToString().Split('/')[1] +"/"+ DateStart.ToString().Split('/')[0] +"/"+ DateStart.ToString().Split('/')[2]);
            //var DateEnd = schdl.Dates.ToString().Split('-')[1];
            //var changeDE = DateTime.Parse(DateEnd.ToString().Split('/')[1] + "/" + DateEnd.ToString().Split('/')[0] + "/" + DateEnd.ToString().Split('/')[2]);
            using (Sep2018Entities metal = new Sep2018Entities())
            {
                KhoaHoc khoahoc = metal.KhoaHocs.Single(p => p.MKH == schdl.CourseID);
                khoahoc.NgayBatDau  = schdl.DateStart;
                khoahoc.NgayKetThuc = schdl.DateEnd;
                metal.SaveChanges();

                for (var i = schdl.DateStart; DateTime.Compare(i, schdl.DateEnd) < 0; i = i.AddDays(1))
                {
                    int day = (int)i.DayOfWeek;
                    if (day == schdl.Days)
                    {
                        var B = new BuoiHoc();
                        B.MKH        = schdl.CourseID;
                        B.GioBatDau  = schdl.Start;
                        B.GioKetThuc = schdl.End;
                        B.Ngay       = i;
                        B.Phong      = schdl.Room;
                        metal.BuoiHocs.Add(B);
                        metal.SaveChanges();
                    }
                }

                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
Ejemplo n.º 9
0
        public void Schedule()
        {
            session.DeleteEach <Order>();
            restore = true;
            var fixture = new CreateSchedule {
                Schedules = new[] {
                    DateTime.Now.AddMinutes(30).TimeOfDay
                }
            };

            Fixture(fixture);

            StartWait();

            dispatcher.Invoke(() => {
                SystemTime.Now = () => DateTime.Now.AddMinutes(20);
                scheduler.AdvanceByMs(30000);
            });

            AsyncClick("Update");
            WaitMessageBox("Обновление завершено успешно.");
            WaitIdle();

            dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
                SystemTime.Now = () => DateTime.Now.AddMinutes(40);
                scheduler.AdvanceByMs(30000);
            }));

            WaitWindow("Обновление");
            dispatcher.Invoke(() => {
                Assert.That(activeWindow.AsText(),
                            Does.Contain("Сейчас будет произведено обновление данных"));
            });
            AsyncClick("TryClose");
            WaitMessageBox("Обновление завершено успешно.");
        }
        public async Task <IActionResult> Create([FromBody] CreateSchedule command)
        {
            await DispatchAsync(command);

            return(Created($"Successfully created schedule with title: '{command.Title}'", null));
        }
Ejemplo n.º 11
0
        public async Task <ActionResult> CreateSchedule(CreateSchedule command)
        {
            await DispatchCommandAsync(command);

            return(CreatedAtAction(nameof(GetSchedule), new { }));
        }
Ejemplo n.º 12
0
        public ActionResult CreateMatches()
        {
            var leaguename = "";
            var cookie     = Request.Cookies["leaguename"];

            if (cookie != null)
            {
                leaguename = cookie.Value;
            }
            ViewBag.LeagueName = leaguename;


            var leagueid = 0;

            cookie = Request.Cookies["leagueid"];
            if (cookie != null)
            {
                int.TryParse(cookie.Value, out leagueid);
            }


            var numOfWeeks = _db.Schedules.Count(x => x.Leagueid == leagueid);
            var numofTeams = _db.Teams.Count(x => x.Leagueid == leagueid);


            var missing = Missing(leagueid);
            //if (missing.Count > 0)
            //{
            //    ViewBag.Error = "Some players not assigned to a team";
            //    return View(missing);
            //}

            var complete = Complete(leagueid);

            if (!complete)
            {
                ViewBag.Error = "Not all teams are complete";
                return(View(missing));
            }

            var matches = _db.Matches.Where(x => x.Team.Leagueid == leagueid).ToList();

            foreach (var match in matches)
            {
                if (match.Team1Score != 0 || match.Team2Score != 0 || match.ForFeitId != 0)
                {
                    ViewBag.Error = "Matches cannot be delete, some matches have scores";
                    return(View(missing));
                }
            }

            _db.Matches.RemoveRange(matches);

            var cs = new CreateSchedule();

            var newMatches = numofTeams % 2 == 0 ? cs.NoByes(numOfWeeks, numofTeams) : cs.Byes(numOfWeeks, numofTeams);

            var scheduleList = _db.Schedules.Where(x => x.Leagueid == leagueid).ToList();
            var lookup       = new Dictionary <int, DateTime>();
            int i            = 1;

            foreach (var item in scheduleList)
            {
                lookup[i++] = item.GameDate;
            }
            var teamList = _db.Teams.Where(x => x.Leagueid == leagueid).ToList();

            foreach (var match in newMatches)
            {
                var team1 = teamList.Find(x => x.TeamNo == match.Team1 + 1);
                var team2 = teamList.Find(x => x.TeamNo == match.Team2 + 1);
                var date  = lookup[match.Week + 1];
                var round = scheduleList.Find(x => x.GameDate == date);
                _db.Matches.Add(new Match()
                {
                    id         = 0,
                    WeekId     = round.id,
                    Rink       = match.Rink == -1 ? -1 : match.Rink + 1,
                    TeamNo1    = team1.id,
                    TeamNo2    = match.Rink == -1? (int?)null : team2.id,
                    Team1Score = 0,
                    Team2Score = 0,
                    ForFeitId  = 0
                });
            }
            try
            {
                _db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
                ViewBag.Error = $"No matches were created, Error {e.Message}";
                return(View(new List <Player>()));
            }
            var rounds = _db.Schedules.Where(x => x.Leagueid == leagueid);

            if (!rounds.Any())
            {
                ViewBag.Error = "No matches created becuse no weeks have been scheduled";
                return(View(missing));
            }
            return(RedirectToAction("index", new { weekid = rounds.First().id, id = leagueid }));
        }