예제 #1
0
        public IActionResult CarpoolCreate(CreateCarpool form)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            User logged_in_user = dbContext.Users.Where(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId"))
                                  .Include(u => u.carpools)
                                  .Include(u => u.riderships)
                                  .ThenInclude(r => r.carpool)
                                  .FirstOrDefault();

            if (ModelState.IsValid)
            {
                Carpool newCarpool = new Carpool()
                {
                    Name   = form.Name,
                    UserId = logged_in_user.Id
                };

                dbContext.Add(newCarpool);
                dbContext.SaveChanges();

                int createdCarpoolId = dbContext.Carpools.Last().Id;
                return(RedirectToAction("CarpoolEdit", new { id = createdCarpoolId }));
            }
            else
            {
                ViewBag.logged_in_user = logged_in_user;
                return(View("Dashboard"));
            }
        }
        public Task <Dictionary <Guid, Passenger> > GetPassengers(Carpool carpool)
        {
            Task <Dictionary <Guid, Passenger> > task = Task.Run(() =>
            {
                Dictionary <Guid, Passenger> listOfpassenger = new Dictionary <Guid, Passenger>();
                using (SqlConnection conn = new SqlConnection(_connString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(_getPassengers, conn))
                    {
                        cmd.Parameters.AddWithValue("@carpoolId", carpool.CarpoolId);
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            Passenger passenger         = new Passenger();
                            passenger.Carpool           = new Carpool();
                            passenger.Carpool.CarpoolId = reader.GetInt32(0);
                            passenger.User       = new User();
                            passenger.User.Id    = reader.GetGuid(1);
                            passenger.IsAccepted = reader.GetBoolean(2);
                            listOfpassenger.Add(passenger.User.Id, passenger);
                        }
                        return(listOfpassenger);
                    }
                }
            });

            return(task);
        }
예제 #3
0
        public IActionResult Carpool(int id, int mappedCommuteId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Carpool carpool = dbContext.Carpools.Where(c => c.Id == id)
                              .Include(c => c.user)
                              .Include(c => c.commutes)
                              .ThenInclude(com => com.startLocation)
                              .Include(c => c.commutes)
                              .ThenInclude(com => com.endLocation)
                              .Include(c => c.riderships)
                              .ThenInclude(r => r.user)
                              .FirstOrDefault();

            Commute clickedCommute = dbContext.Commutes
                                     .Include(c => c.startLocation)
                                     .Include(c => c.endLocation)
                                     .FirstOrDefault(c => c.Id == mappedCommuteId);

            User logged_in_user = dbContext.Users.FirstOrDefault(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId"));

            ViewBag.logged_in_user = logged_in_user;
            ViewBag.ClickedCommute = clickedCommute;
            return(View(carpool));
        }
        public void CarpoolGetFromDatabaseTest()
        {
            //Arrange
            Carpool        carpool  = GetCarpool();
            List <Carpool> carpools = new List <Carpool>();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId = carpool1.CarpoolId;
                    carpools.Add(carpool1);
                }
            }

            Carpool carpool2 = new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result;

            //Act & Assert
            Assert.AreEqual(carpool.CarpoolId, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.CarpoolId);
            //Assert.AreEqual(carpool.Date,new CarpoolDatabaseAsync().GetCarpool(carpools[0].CarpoolId).Result.Date); is the same value
            Assert.AreEqual(carpool.Details, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.Details);
            Assert.AreEqual(carpool.Driver.Id, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.Driver.Id);
            Assert.AreEqual(carpool.PassengerSeats, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.PassengerSeats);
            Assert.AreEqual(carpool.Branch.BranchId, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.Branch.BranchId);
            Assert.AreEqual(carpool.Branch.BranchName, new CarpoolPersistenceAsync().GetCarpool(carpools[0].CarpoolId).Result.Branch.BranchName);

            Assert.IsNotNull(new CarpoolPersistenceAsync().GetCarpool(100000));
        }
예제 #5
0
        public void Remove(int id)
        {
            Carpool carpool = context.Carpools.Find(id);

            context.Carpools.Remove(carpool);
            context.SaveChanges();
        }
예제 #6
0
        public IActionResult CarpoolDelete(int id)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Carpool carpoolToRemove = dbContext.Carpools.Where(c => c.Id == id)
                                      .Include(c => c.user)
                                      .FirstOrDefault();

            User logged_in_user = dbContext.Users.Where(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId"))
                                  .Include(u => u.carpools)
                                  .Include(u => u.riderships)
                                  .ThenInclude(r => r.carpool)
                                  .FirstOrDefault();

            if (carpoolToRemove is null)
            {
                ViewBag.logged_in_user = logged_in_user;
                ModelState.AddModelError("Error", "Carpool for deletion does not exist");
                return(View("Dashboard"));
            }
            if (logged_in_user.Id == carpoolToRemove.user.Id)
            {
                dbContext.Remove(carpoolToRemove);
                dbContext.SaveChanges();
                ViewBag.logged_in_user = logged_in_user;
                return(RedirectToAction("Dashboard"));
            }

            ViewBag.logged_in_user = logged_in_user;
            ModelState.AddModelError("Error", "Insufficient privileges to delete that carpool");
            return(View("Dashboard"));
        }
예제 #7
0
        public IActionResult RidershipKick(int userId, int carpoolId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            User logged_in_user = dbContext.Users.Where(u => u.Id == HttpContext.Session.GetInt32("LoggedInUserId"))
                                  .Include(u => u.carpools)
                                  .Include(u => u.riderships)
                                  .ThenInclude(r => r.carpool)
                                  .FirstOrDefault();

            Carpool carpool = dbContext.Carpools.Where(c => c.Id == carpoolId)
                              .Include(c => c.user)
                              .FirstOrDefault();

            if (HttpContext.Session.GetInt32("LoggedInUserId") == carpool.user.Id)
            {
                Ridership ridershipToRemove = dbContext.Riderships.Where(r => (r.CarpoolId == carpoolId) && (r.UserId == userId))
                                              .FirstOrDefault();
                dbContext.Remove(ridershipToRemove);
                dbContext.SaveChanges();


                ViewBag.logged_in_user = logged_in_user;

                return(Redirect($"/carpool/edit/{carpoolId}"));
            }

            ViewBag.logged_in_user = logged_in_user;
            ModelState.AddModelError("Error", "Insufficient privileges to kick user");
            return(View("Dashboard", "Carpool"));
        }
        public Carpool MakeCarpool(SqlDataReader sqlReader)
        {
            Carpool carpool1 = new Carpool();

            carpool1.Driver             = new User();
            carpool1.Driver.AddressList = new List <Address>();
            carpool1.Branch             = new Branch();
            Address address1 = new Address();

            carpool1.Driver.Id          = sqlReader.GetGuid(0);
            carpool1.Driver.Name        = sqlReader.GetString(1);
            carpool1.Driver.Surname     = sqlReader.GetString(2);
            carpool1.Driver.Email       = sqlReader.GetString(3);
            carpool1.Driver.Phonenumber = sqlReader.GetString(4);

            address1.StreetName   = sqlReader.GetString(5);
            address1.StreetNumber = sqlReader.GetString(6);
            if (sqlReader.GetDouble(7) != 0)
            {
                address1.Latitude   = sqlReader.GetDouble(7);
                address1.Longtitude = sqlReader.GetDouble(8);
            }
            address1.CityName   = sqlReader.GetString(9);
            address1.Postalcode = sqlReader.GetInt32(10);
            carpool1.Driver.AddressList.Add(address1);
            carpool1.CarpoolId         = sqlReader.GetInt32(11);
            carpool1.Branch.BranchId   = sqlReader.GetInt32(12);
            carpool1.PassengerSeats    = sqlReader.GetInt32(13);
            carpool1.Date              = sqlReader.GetDateTime(14);
            carpool1.HomeAdress        = sqlReader.GetBoolean(15);
            carpool1.Branch.BranchName = sqlReader.GetString(16);
            carpool1.Details           = sqlReader.GetString(17);
            carpool1.Passengerlist     = new Dictionary <Guid, Passenger>();
            return(carpool1);
        }
        public Task <bool> DeletePassenger(User user, Carpool carpool)
        {
            Task <bool> task = Task.Run(() =>
            {
                using (SqlConnection conn = new SqlConnection(_connString))
                {
                    conn.Open();

                    using (SqlCommand cmd = new SqlCommand(_deletePassenger, conn))
                    {
                        cmd.Parameters.AddWithValue("@CarpoolId", carpool.CarpoolId);
                        cmd.Parameters.AddWithValue("@UserId", user.Id);

                        int rowsAffected = cmd.ExecuteNonQuery();

                        if (rowsAffected == 0)
                        {
                            return(false);

                            throw new AggregateException("Der blev ikke deleted passager id: " + user.Id);
                        }
                        return(true);
                    }
                }
            });

            return(task);
        }
예제 #10
0
        public int CreateCarpool(CarpoolCreationRequestDto carpool)
        {
            var addressObj = _addressDetails.Get(
                carpool.Address.StreetNumber,
                carpool.Address.City,
                carpool.Address.State,
                carpool.Address.ZipCode);

            if (addressObj == null)
            {
                addressObj = new Address
                {
                    StreetNumber = carpool.Address.StreetNumber,
                    City         = carpool.Address.City,
                    State        = carpool.Address.State,
                    ZipCode      = carpool.Address.ZipCode,
                };

                _addressDetails.Add(addressObj);
            }

            var campusObj = _campusDetails.Get(carpool.CampusName);

            if (campusObj == null)
            {
                campusObj = new Campus
                {
                    Address = addressObj,
                    Name    = carpool.CampusName,
                };

                _campusDetails.Add(campusObj);
            }

            var newCarpool = new Carpool
            {
                Campus       = campusObj,
                Certificates = new List <Certificate>
                {
                    new Certificate
                    {
                        CreateDate    = DateTime.Now,
                        ExpiryDate    = DateTime.Now.AddDays(365),
                        IncentiveType = _carpoolDetails.GetIncentiveType(carpool.IncentiveId),
                    }
                }
            };

            _carpoolDetails.AddCarpool(newCarpool);

            var owner    = _userDetails.GetUserModel(carpool.UserEmail);
            var userType = _userDetails.GetUserType("Carpool Owner");

            owner.UserType = userType;
            owner.Carpool  = newCarpool;
            _userDetails.Update(owner);
            return(newCarpool.Id);
        }
        public void CarpoolAddToDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            //Act & Assert
            Assert.IsTrue(new CarpoolPersistenceAsync().AddCarpool(carpool).Result);
            Assert.ThrowsException <AggregateException>(() => new CarpoolPersistenceAsync().AddCarpool(new Carpool()).Result);
        }
예제 #12
0
 public void MapTo(Carpool carpool)
 {
     Id            = carpool.Id;
     Name          = carpool.Name;
     CarType       = carpool.CarType;
     Color         = carpool.Color;
     Plates        = carpool.Plates;
     NumberOfSeats = carpool.NumberOfSeats;
 }
        public Task <Dictionary <int, Carpool> > GetAllCarpools(Guid userId)
        {
            Task <Dictionary <int, Carpool> > task = Task.Run(() =>
            {
                Carpool carpool = new Carpool();
                Dictionary <int, Carpool> carpools = new Dictionary <int, Carpool>();


                using (SqlConnection conn = new SqlConnection(_connString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(_getAllUserCarpools, conn))
                    {
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            carpool = MakeCarpool(reader);
                            carpools.Add(carpool.CarpoolId, carpool);
                        }
                        cmd.Dispose();
                        reader.Close();
                    }

                    using (SqlCommand cmd = new SqlCommand(_getAllUserPassengers, conn))
                    {
                        cmd.Parameters.AddWithValue("@user", userId);
                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            Passenger passenger         = new Passenger();
                            passenger.Carpool           = new Carpool();
                            passenger.Carpool.CarpoolId = reader.GetInt32(0);
                            passenger.User       = new User();
                            passenger.User.Id    = reader.GetGuid(1);
                            passenger.IsAccepted = reader.GetBoolean(2);
                            if (carpools.ContainsKey(passenger.Carpool.CarpoolId))
                            {
                                carpools[passenger.Carpool.CarpoolId].Passengerlist.Add(passenger.User.Id, passenger);
                            }
                        }
                    }



                    return(carpools);
                }
            });

            return(task);
        }
예제 #14
0
        // GET: Carpools/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Carpool carpool = _carpoolRepository.FindById(Convert.ToInt32(id));

            if (carpool == null)
            {
                return(HttpNotFound());
            }
            return(View(carpool));
        }
예제 #15
0
        public IActionResult CarpoolUpdate(string Name, string Description, int CarpoolId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Carpool thisCarpool = dbContext.Carpools.Where(c => c.Id == CarpoolId).FirstOrDefault();

            thisCarpool.Name        = Name;
            thisCarpool.Description = Description;
            dbContext.Update(thisCarpool);
            dbContext.SaveChanges();
            return(RedirectToAction("CarpoolDefault", new { id = CarpoolId }));
        }
예제 #16
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(/*[Bind(Include = "Id,StartLocation,EndLocation,StartDate,EndDate")]*/ TravelPlanModel travelPlan)
        {
            bool success = false;

            if (ModelState.IsValid)
            {
                try
                {
                    Carpool         car       = _carpoolRepository.FindById(travelPlan.CarId);
                    List <Employee> employees = _employeeRepository.FindByIds(travelPlan.EmployeeIds).ToList();
                    if (travelPlan.HasDriver && car.NumberOfSeats >= travelPlan.EmployeeIds.Count)
                    {
                        TravelPlan result = new TravelPlan()
                        {
                            StartLocation = travelPlan.StartLocation,
                            EndLocation   = travelPlan.EndLocation,
                            StartDate     = travelPlan.StartDate,
                            EndDate       = travelPlan.EndDate,
                            CarId         = travelPlan.CarId,
                            Car           = car
                        };
                        result.EmployeeTravelPlans = new List <EmployeeTravelPlan>();
                        foreach (var el in employees)
                        {
                            result.EmployeeTravelPlans.Add(new EmployeeTravelPlan()
                            {
                                Employee   = el,
                                EmployeeId = el.Id,
                                TravelPlan = result
                            });
                        }
                        _travelPlanRepository.Add(result);
                        success = true;
                        return(Json(new{ success }));
                    }
                    else
                    {
                        return(Json(new { success }));
                    }
                }
                catch (Exception exe)
                {
                    ModelState.AddModelError("", exe.Message);
                }
            }

            return(Json(new { success }));
        }
        public void CarpoolDeletePassengerToDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId = carpool1.CarpoolId;
                }
            }

            //Act & Assert needs a carpool to be added
            Assert.IsTrue(new CarpoolPersistenceAsync().DeletePassenger(carpool.Driver, carpool).Result);
        }
        public void CarpoolgetPassengersFromDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId = carpool1.CarpoolId;
                }
            }

            //Act & Assert needs a carpool to be added
            Assert.AreEqual(carpool.Driver.Id, new CarpoolPersistenceAsync().GetPassengers(carpool).Result[carpool.Driver.Id].User.Id);
        }
        public void CarpoolDeleteFromDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId = carpool1.CarpoolId;
                }
            }

            //Act & Assert
            Assert.IsTrue(new CarpoolPersistenceAsync().DeleteCarpool(carpool.CarpoolId).Result);
        }
        public Task <Carpool> GetCarpool(int idCarpool)
        {
            Task <Carpool> task = Task.Run(() =>
            {
                Carpool carpool = new Carpool();

                using (SqlConnection conn = new SqlConnection(_connString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(_getCarpool, conn))
                    {
                        cmd.Parameters.AddWithValue("@carpoolId", idCarpool);
                        SqlDataReader reader = cmd.ExecuteReader();
                        reader.ReadAsync();
                        if (!reader.HasRows)
                        {
                            throw new AggregateException("Der var ingen carpools med det id " + idCarpool);
                        }
                        else
                        {
                            carpool = MakeCarpool(reader);
                        }
                        cmd.Dispose();
                        reader.Close();
                    }

                    using (SqlCommand cmd = new SqlCommand(_getPassengers, conn))
                    {
                        cmd.Parameters.AddWithValue("@carpoolId", carpool.CarpoolId);
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            Passenger passenger         = new Passenger();
                            passenger.Carpool           = new Carpool();
                            passenger.Carpool.CarpoolId = reader.GetInt32(0);
                            passenger.User       = new User();
                            passenger.User.Id    = reader.GetGuid(1);
                            passenger.IsAccepted = reader.GetBoolean(2);
                            carpool.Passengerlist.Add(passenger.User.Id, passenger);
                        }
                    }
                    return(carpool);
                }
            });

            return(task);
        }
        public void CarpoolUpdatePassengersFromDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId     = carpool1.CarpoolId;
                    carpool.Passengerlist = carpool1.Passengerlist;
                    carpool.Passengerlist[carpool.Driver.Id].IsAccepted = true;
                }
            }

            //Act & Assert needs a carpool to be added
            Assert.IsNotNull(new CarpoolPersistenceAsync().UpdatePassenger(carpool.Driver.Id, carpool.CarpoolId).Result);
        }
        public void CarpoolAddPassengerToDatabaseTest()
        {
            //Arrange
            Carpool carpool = GetCarpool();

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(carpool.Driver.Id).Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool.CarpoolId = carpool1.CarpoolId;
                }
            }

            //Act & Assert needs a carpool to be added
            Assert.IsTrue(new CarpoolPersistenceAsync().AddPassenger(new UserDatabaseTest().GetUser(), carpool).Result);

            Assert.ThrowsException <AggregateException>(() => new CarpoolPersistenceAsync().AddPassenger(new User(), new Carpool()).Result);
        }
예제 #23
0
        protected override IActionResult GetRequest()
        {
            Carpool      = new Carpool();
            Carpool.Date = DateTime.Today;
            List <System.Security.Claims.Claim> listofClaims = User.Claims.ToList();

            Carpool.Driver = _userInterface.GetUser(Guid.Parse(listofClaims[0].Value)).Result;
            List <Branch> allBranches = _carpoolInterface.GetBranches().Result;
            Branch        homeadress  = new Branch();

            homeadress.BranchId         = 0;
            homeadress.BranchName       = Carpool.Driver.AddressList[0].StreetName + " " + Carpool.Driver.AddressList[0].StreetNumber + " " + Carpool.Driver.AddressList[0].CityName + " " + Carpool.Driver.AddressList[0].Postalcode;
            homeadress.BranchPostalCode = Carpool.Driver.AddressList[0].Postalcode;
            allBranches.Add(homeadress);
            Branches = new SelectList(allBranches, nameof(Branch.BranchId), nameof(Branch.BranchName));

            return(Page());
        }
        public Carpool GetCarpool()
        {
            DateTime time    = DateTime.Parse("13-05-2021 11:43:32");
            Carpool  carpool = new Carpool();

            carpool.Branch                  = new Branch();
            carpool.Branch.BranchId         = 1;
            carpool.Branch.BranchName       = "Zealand Roskilde";
            carpool.Branch.BranchPostalCode = 4000;


            carpool.Driver        = new UserDatabaseTest().GetUser();
            carpool.Passengerlist = new Dictionary <System.Guid, Passenger>();

            carpool.Date           = time;
            carpool.Details        = "Dette er detaljer";
            carpool.PassengerSeats = 3;
            return(carpool);
        }
        public void CarpoolgetCarpoolsAllSearchFromDatabaseTest()
        {
            //Arrange
            Carpool  carpool  = GetCarpool();
            Carpool  carpool2 = new Carpool();
            DateTime time     = DateTime.Parse("13-01-2021 11:43:32");

            foreach (Carpool carpool1 in new CarpoolPersistenceAsync().GetAllCarpools(time, "Zealand").Result.Values)
            {
                if (carpool.Driver.Id == carpool1.Driver.Id)
                {
                    carpool2 = carpool1;
                }
            }

            //Act & Assert needs a carpool to be added to the database
            Assert.AreEqual(carpool.CarpoolId, carpool.CarpoolId);
            Assert.AreEqual(carpool.Branch.BranchId, carpool2.Branch.BranchId);
            Assert.AreEqual(carpool.Driver.Id, carpool2.Driver.Id);
        }
예제 #26
0
 public ActionResult Edit([Bind(Include = "Id,Name,CarType,Color,Plates,NumberOfSeats")] Carpool carpool)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (_carpoolRepository.IsUniquePlates(carpool.Plates, carpool.Id))
             {
                 _carpoolRepository.Edit(carpool);
                 return(RedirectToAction("Index"));
             }
             ModelState.AddModelError("", "Plates already exist.");
         }
         catch (Exception exe)
         {
             ModelState.AddModelError("", exe.Message);
         }
     }
     return(View(carpool));
 }
        public Task <bool> AddCarpool(Carpool carpool)
        {
            Task <bool> task = Task.Run(() =>
            {
                using (SqlConnection conn = new SqlConnection(_connString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(_addCarpool, conn))
                    {
                        cmd.Parameters.AddWithValue("@UserId", carpool.Driver.Id);
                        cmd.Parameters.AddWithValue("@Branch", carpool.Branch.BranchId);
                        cmd.Parameters.AddWithValue("@PassengerSeats", carpool.PassengerSeats);
                        cmd.Parameters.AddWithValue("@Date", carpool.Date);
                        cmd.Parameters.AddWithValue("@Home", carpool.HomeAdress);

                        if (carpool.Details is null)
                        {
                            carpool.Details = "";
                        }
                        cmd.Parameters.AddWithValue("@Detail", carpool.Details);

                        int rowsAffected = cmd.ExecuteNonQuery();

                        if (rowsAffected == 0)
                        {
                            return(false);

                            throw new AggregateException("Der blev ikke tilføjet carpool, brugerID: " + carpool.Driver.Id);
                        }
                        return(true);
                    }
                }
            });

            return(task);
        }
예제 #28
0
 public void Edit(Carpool carpool)
 {
     context.Entry(carpool).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
예제 #29
0
 public void Add(Carpool carpool)
 {
     context.Carpools.Add(carpool);
     context.SaveChanges();
 }
예제 #30
0
 public async Task UpdateAsync(Carpool item)
 {
     await _repository.UpdateAsync(item);
 }