///<summary>
        /// metoda dodająca nową transakcję
        ///</summary>
        public async Task <string> AddTransaction(Transaction Transaction)
        {
            try
            {
                dbContext.Transaction.Add(Transaction);
                await dbContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(await Task.FromResult(e.ToString()));
            }

            var newCar = new UserCars();

            newCar.AspNetUsers_Id = Transaction.User;
            newCar.DB_Car_idCar   = Transaction.Car;

            var car = await dbContext.Car.FindAsync(Transaction.Car);

            car.IsAvailable = 0;
            dbContext.Car.Update(car);

            dbContext.UserCars.Add(newCar);

            await dbContext.SaveChangesAsync();

            return(await Task.FromResult("OK"));
        }
示例#2
0
 /// <summary>
 /// Writes short description of a user. Name, age, number of owned cars.
 /// </summary>
 /// <returns></returns>
 public string WriteUserShortDescription()
 {
     UserAge         = GetUserAge();
     UserOwnedCars   = UserCars.Count();
     UserDescription = string.Format("{0},{1},{2}", Name, UserAge, UserOwnedCars);
     return(UserDescription);
 }
        public ActionResult SearchCarInfo(int?id)
        {
            UserCars car = unitOfWork.UserCars.Get(id);

            ViewBag.From = car;
            return(View(car));
            //return View("~/Views/Search/SearchCargoInfo.cshtml");
            ///////////////////
        }
示例#4
0
 public async Task <IActionResult> OnGet(string UserId)
 {
     UserCars = new UserCars
     {
         User = await _db.ApplicationUser.FirstOrDefaultAsync(m => m.Id == UserId),
         Cars = await _db.Car.Where(m => m.UserId == UserId).ToListAsync()
     };
     return(Page());
 }
示例#5
0
 /// <summary>
 /// Removes car from user's car list by Brand, Model, ProductionYear.
 /// </summary>
 /// <param name="Brand"></param>
 /// <param name="Model"></param>
 /// <param name="ProductionYear"></param>
 public void RemoveCar(String vin)
 {
     try
     {
         UserCars.Remove(UserCars.First(c => c.Vin == vin));
         MessageBox.Show("Car deleted!", "Success!");
     }
     catch (Exception)
     {
         MessageBox.Show("Car could not be found!", "Failure");
     }
 }
示例#6
0
 public Car FindCarByVin(string vin)
 {
     try
     {
         var car = UserCars.First(c => c.Vin == vin);
         return(car);
     }
     catch (Exception)
     {
         MessageBox.Show("Car could not be found!", "Failure!");
         return(new Car());
     }
 }
示例#7
0
        public void AddUserCar([FromBody] UserCars car)
        {
            currentUserId = User.Identity.GetUserId();
            ApplicationUser user   = UserManager.FindById(currentUserId);
            var             number = UserManager.GetPhoneNumber(currentUserId);

            car.UserAdress  = user.Adress;
            car.UserName    = user.Name + " " + user.Surname;
            car.PhoneNumber = number;
            car.UserId      = currentUserId;
            unitOfWork.UserCars.Create(car);
            unitOfWork.Save();
        }
示例#8
0
        /// <summary>
        /// Finds car in user's car list by Brand, Model and ProductionYear.
        /// </summary>
        /// <param name="brand"></param>
        /// <param name="model"></param>
        /// <param name="productionYear"></param>
        /// <returns></returns>
        public List <Car> FindCar(string brand, string model, int productionYear)
        {
            try
            {
                var foundCar = UserCars
                               .Where(c => c.Brand == brand)
                               .Where(c => c.Model == model)
                               .Where(c => c.ProductionDate.Year == productionYear);
                return(new List <Car>(foundCar));
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Car could not be found!", "Failure!");
                return(new List <Car>());
            }

            //List<int> brandList = FindCarBrand(brand);
            //List<int> modelList = FindCarModel(model);
            //List<int> yearList = FindCarYear(productionYear);
            //List<int> foundCars = CompareLists(brandList, modelList, yearList);
        }
示例#9
0
 /// <summary>
 /// Method adds new car to the user's car list "userCars".
 /// </summary>
 /// <param name="newCar"></param>
 public void AddNewCar(Car newCar)
 {
     UserCars.Add(newCar);
 }
示例#10
0
 public IEnumerable <UserCars> Find([FromUri] UserCars car)
 {
     return(unitOfWork.UserCars.Find(car));
 }