Beispiel #1
0
        public void Test_getActivity()
        {
            IActivity          a = new Mocked_Activity();
            IScheduledActivity o = new ScheduledActivity(a, DT);

            Assert.AreSame(a, o.getActivity());
        }
Beispiel #2
0
        public void Test_ScheduledActivityInstance()
        {
            IActivity          a = new Mocked_Activity();
            IScheduledActivity o = new ScheduledActivity(a, DT);

            Assert.AreNotSame(o, null);
        }
        public async Task <IActionResult> Edit(long id, [Bind("Id,DueDate")] ScheduledActivity scheduledActivity)
        {
            if (id != scheduledActivity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(scheduledActivity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ScheduledActivityExists(scheduledActivity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(scheduledActivity));
        }
        public async Task <IActionResult> Check(int [] Checked)
        {
            if (!isLogedIn())
            {
                return(RedirectToRoute("Home"));
            }
            Name        = HttpContext.Session.GetString("Name");
            CompanyName = HttpContext.Session.GetString("CompanyName");
            CompanyId   = (int)HttpContext.Session.GetInt32("CompanyId");
            int VehicleId = (int)HttpContext.Session.GetInt32("VehicleId");

            ViewData["Name"]          = Name;
            ViewData["CompanyName"]   = CompanyName;
            ViewData["Id"]            = VehicleId;
            ViewData["Notifications"] = NotificationManager.GetNotifications(CompanyId, _context);
            foreach (int ServiceId in Checked)
            {
                ScheduledActivity S = _context.ScheduledActivities.Where(s => s.Id == ServiceId)
                                      .Include(s => s.Activity).Single();
                S.DueDate = DateTime.Now.AddDays(S.Activity.Period);
                _context.Update(S);
            }
            _context.SaveChanges();
            ScheduledActivity[] scheduledActivities = _context.ScheduledActivities
                                                      .Where(s => s.Vehicle.Id == VehicleId).Include(s => s.Activity).OrderBy(s => s.DueDate).ToArray <ScheduledActivity>();
            return(View("/Views/VehiclesDetails/ScheduledServices.cshtml", scheduledActivities));
        }
Beispiel #5
0
        public void Test_ToString()
        {
            IActivity          a        = new Mocked_Activity();
            IScheduledActivity o        = new ScheduledActivity(a, DT);
            string             actual   = o.ToString();
            string             expected = TIMETEXT + " : " + Mocked_Activity.TEXT;

            Assert.AreEqual(actual, expected);
        }
Beispiel #6
0
        public void Test_getEnd()
        {
            IActivity          a = new Mocked_Activity();
            IScheduledActivity o = new ScheduledActivity(a, DT);

            DateTime actual   = o.getEnd();
            DateTime expected = DT.Add(new TimeSpan(0, Mocked_Activity.DURATION, 0));

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void Test_getStart()
        {
            IActivity          a = new Mocked_Activity();
            IScheduledActivity o = new ScheduledActivity(a, DT);

            DateTime actual   = o.getStart();
            DateTime expected = DT;

            Assert.AreEqual(expected, actual);
        }
        public async Task <IActionResult> Create([Bind("Id,DueDate")] ScheduledActivity scheduledActivity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(scheduledActivity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(scheduledActivity));
        }
        public async Task <IActionResult> FinishAddPlanToVehicles(long [] SelectedVehicles)
        {
            if (!isLogedIn())
            {
                return(RedirectToRoute("Home"));
            }
            CompanyId = (int)HttpContext.Session.GetInt32("CompanyId");
            ViewData["Notifications"] = NotificationManager.GetNotifications(CompanyId, _context);
            int N = SelectedVehicles.Length;

            Vehicle[] vehicles = new Vehicle[N];
            long      PlanId   = (long)HttpContext.Session.GetInt32("PlanId");
            Plan      plan     = _context.Plan.Find(PlanId);
            DateTime  dateTime = DateTime.Now;

            Activity[] activities = _context.Activities.Where(a => a.Plan.Id == PlanId).ToArray <Activity>();
            int        M          = activities.Length;

            ScheduledActivity[] scheduledActivities = new ScheduledActivity[N * M];

            for (int i = 0; i < N; i++)
            {
                vehicles[i] = await _context.Vehicles.FindAsync(SelectedVehicles[i]);

                vehicles[i].Plan = plan;
                _context.ScheduledActivities.RemoveRange(_context.ScheduledActivities.Where(s => s.Vehicle == vehicles[i]));

                for (int j = 0; j < M; j++)
                {
                    scheduledActivities[i * M + j]           = new ScheduledActivity();
                    scheduledActivities[i * M + j].Activity  = activities[j];
                    scheduledActivities[i * M + j].Vehicle   = vehicles[i];
                    scheduledActivities[i * M + j].CompanyId = CompanyId;
                    scheduledActivities[i * M + j].DueDate   = dateTime.AddDays(activities[j].Period);
                }
            }
            _context.UpdateRange(vehicles);
            _context.AddRange(scheduledActivities);
            await _context.SaveChangesAsync();

            Name                         = HttpContext.Session.GetString("Name");
            CompanyName                  = HttpContext.Session.GetString("CompanyName");
            ViewData["Name"]             = Name;
            ViewData["CompanyName"]      = CompanyName;
            ViewData["QueryPlaceHolder"] = "Vehicles";
            return(RedirectToAction("Index"));
        }