public async Task <ActionResult> DeleteConfirmed(int id)
        {
            ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

            db.ServicePointWorkers.Remove(servicePointWorker);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        // GET: ServicePointWorkers/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

            if (servicePointWorker == null)
            {
                return(HttpNotFound());
            }
            return(View(servicePointWorker));
        }
        public async Task <ActionResult> Edit([Bind(Include = "id,firstName,lastName,age,salary,employed")] ServicePointWorker servicePointWorker)
        {
            if (servicePointWorker.employed > DateTime.Today)
            {
                ModelState.AddModelError("employed", "Data nie może być większa od obecnej");
            }
            if (ModelState.IsValid)
            {
                db.Entry(servicePointWorker).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(servicePointWorker));
        }
        public async Task <ActionResult> DeleteServicePoint(string name, int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (name == null)
            {
                ModelState.AddModelError("lastName", "Nie wybrałeś pracownika");
            }
            if (ModelState.IsValid)
            {
                ServicePoint       servicePoint       = db.ServicePoints.Where(x => x.name == name).FirstOrDefault();
                ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

                servicePoint.ServicePointWorkers.Remove(servicePointWorker);
                servicePointWorker.ServicePoints.Remove(servicePoint);

                db.Entry(servicePoint).State       = EntityState.Modified;
                db.Entry(servicePointWorker).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = servicePointWorker.id }));
            }
            else
            {
                ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

                if (servicePointWorker == null)
                {
                    return(HttpNotFound());
                }
                var servicePointWorkerServicePoints = servicePointWorker.ServicePoints.Select(x => x.name).ToList();
                IEnumerable <ServicePoint> availableServicePoints = db.ServicePoints.
                                                                    Where(x => servicePointWorkerServicePoints.
                                                                          Contains(x.name));


                ViewBag.name = new SelectList(availableServicePoints, "name", "name");
                return(View(servicePointWorker));
            }
        }
        // GET: ServicePointWorkers/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

            foreach (var item in servicePointWorker.ServicePoints)
            {
                item.howManyWorkers = item.ServicePointWorkers.Count();
            }
            await db.SaveChangesAsync();

            if (servicePointWorker == null)
            {
                return(HttpNotFound());
            }
            return(View(servicePointWorker));
        }
        //GET: Runways/AddServicePoint/5
        public async Task <ActionResult> AddServicePoint(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ServicePointWorker servicePointWorker = await db.ServicePointWorkers.FindAsync(id);

            if (servicePointWorker == null)
            {
                return(HttpNotFound());
            }
            var servicePointWorkerServicePoints = servicePointWorker.ServicePoints.Select(x => x.name).ToList();
            IEnumerable <ServicePoint> availableServicePoints = db.ServicePoints.
                                                                Where(x => !servicePointWorkerServicePoints.
                                                                      Contains(x.name));


            ViewBag.name = new SelectList(availableServicePoints, "name", "name");
            return(View(servicePointWorker));
        }