Пример #1
0
        public ActionResult ListYourCar(Car car)
        {
            if (Session["user"] != null)
            {
                Models.User user = (Models.User)Session["user"];

                car = db.Cars.Add(car);
                db.SaveChanges();

                //save it as user car.

                UserCar userCar = new UserCar();
                userCar.CarId  = car.CarId;
                userCar.UserId = user.UserId;
                userCar.Status = "Active";

                db.UserCars.Add(userCar);
                db.SaveChanges();

                return(RedirectToAction("MyCars", "Car"));
            }
            else
            {
                return(RedirectToAction("Index", "User"));
            }
        }
Пример #2
0
        static int GetSpeed(User user, UserCar userCar)
        {
            var car = userCar.Auto;

            return(user.Attentiveness * car.Speed + user.SpeedReaction * car.Mobility +
                   user.Cunning * car.Overclocking + user.Courage * car.Braking);
        }
Пример #3
0
 public static void Activate(this UserCar car, InUpdateCarAssignmentsDTO carAssignmentsDTO)
 {
     car.Mileage           = carAssignmentsDTO.Mileage;
     car.StartOfAssignment = DateTimeOffset
                             .FromUnixTimeSeconds(carAssignmentsDTO.DateOfAssignment).UtcDateTime;
     car.Active          = true;
     car.Deleted         = false;
     car.EndOfAssignment = null;
 }
Пример #4
0
        public async Task DeleteAsync(UserCar userCar)
        {
            if (userCar == null)
            {
                return;
            }

            this.context.Remove(userCar);
            await this.context.SaveChangesAsync();
        }
Пример #5
0
        /// <summary>
        /// Рассчитать результат участника гонки
        /// </summary>
        static UserRaceResult GetRaceResult(GroupRaceParticipant raceParticipant)
        {
            var     user    = raceParticipant.User;
            UserCar userCar = raceParticipant.UserCar;

            return(new UserRaceResult()
            {
                User = user, Speed = GetSpeed(user, userCar)
            });
        }
Пример #6
0
        public async Task AddAsync(UserCar userCar)
        {
            if (userCar == null)
            {
                return;
            }

            await this.context.UserCars.AddAsync(userCar);

            await this.context.SaveChangesAsync();
        }
Пример #7
0
        /// <summary>
        /// Получить скорость
        /// </summary>
        static int GetSpeed(User user, UserCar userCar)
        {
            var car    = userCar.Auto;
            var random = new Random();
            var a1     = random.Next(user.Attentiveness, user.Attentiveness + user.Luck) * car.Speed;
            var a2     = random.Next(user.SpeedReaction, user.SpeedReaction + user.Luck) * car.Mobility;
            var a3     = random.Next(user.Cunning, user.Cunning + user.Luck) * car.Overclocking;
            var a4     = random.Next(user.Courage, user.Courage + user.Luck) * car.Braking;

            return(a1 + a2 + a3 + a4);
        }
Пример #8
0
        public IActionResult getUser(int id)
        {
            var userParking = _dataContext.users.FirstOrDefault(u => u.Id == id);
            var carParking  = _dataContext.cars.FirstOrDefault(c => c.IdCar == userParking.Id);
            var userWithCar = new UserCar {
                IdUserCar = userParking.Id,
                user      = userParking,
                car       = carParking
            };

            if (userWithCar == null)
            {
                return(NotFound());
            }
            return(Ok(userWithCar));
        }
Пример #9
0
 internal static OutAssignedCarDTO Map(UserCar userCar)
 {
     return(new OutAssignedCarDTO
     {
         Active = userCar.Active,
         StartOfAssignment = userCar.StartOfAssignment,
         EndOfAssignment = userCar.EndOfAssignment,
         Mileage = userCar.Mileage,
         User = new OutUserDTO
         {
             Id = userCar.User.Id,
             FirstName = userCar.User.FirstName,
             LastName = userCar.User.LastName,
             DateOfBirth = userCar.User.DateOfBirth,
             DateOfEmployment = userCar.User.DateOfEmployment,
             Email = userCar.User.Email,
             PhoneNumber = userCar.User.PhoneNumber
         }
     });
 }
Пример #10
0
        public async Task <bool> AddUserCarAsync(string userId, int modelId)
        {
            var result = await this.db.UserCars.FindAsync(userId, modelId);

            if (result != null)
            {
                return(false);
            }

            var userCar = new UserCar
            {
                UserId  = userId,
                ModelId = modelId
            };

            await this.db.AddAsync(userCar);

            this.db.SaveChanges();

            return(true);
        }
Пример #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(openFile.FileName);
                UserCar  userCar  = new UserCar();
                userCar.Marka        = cmbx_marka.Text;
                userCar.Model        = cmbx_model.Text;
                userCar.City         = cmbx_city.Text;
                userCar.Year         = cmbx_year.Text;
                userCar.Desicription = txbx_desc.Text;
                userCar.Prize        = txbx_prize.Text;
                userCar.Photo        = fileInfo.Name;
                userCar.Currency     = valyuta;
                userCar.UserId       = DbExtensions.UserId(dbContext, users, label8.Text);


                string photoPath = ConfigurationManager.AppSettings["Path"].ToString();
                string fullPath  = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\", photoPath, userCar.Photo));
                byte[] array     = null;
                using (FileStream fileStream = File.Open(openFile.FileName, FileMode.Open))
                {
                    array = new byte[fileStream.Length];
                    fileStream.Read(array, 0, array.Length);
                }

                using (FileStream fileStream = File.Create(fullPath))
                {
                    fileStream.Write(array, 0, array.Length);
                }

                dbContext.InsertCommandUserCars(userCar.GetType(), userCar.Marka, userCar.Model, userCar.City, userCar.Year, userCar.Desicription, userCar.Prize, userCar.Photo, userCar.UserId, userCar.Currency);
                txbx_excPhoto.Text = "Elaniniz Ugurla Yerlesdirildi";
            }
            catch (Exception ex)
            {
                txbx_excPhoto.Text = ex.Source = "Zehmet Olmasa Photonu Secin";
                string str = ex.Message;
            }
        }
        public async Task <ServiceResult> UseShareKeyAsync(Guid userId, Guid shareKeyId)
        {
            var shareKey = await _shareKeyRepository.GetShareKeyByIdAsync(shareKeyId);

            if (shareKey == null)
            {
                return(FailedResult("Invalid share key", 400));
            }

            if (shareKey.Used)
            {
                return(FailedResult("This share key has been used", 400));
            }

            if (await UserHasCar(userId, shareKey.CarId, shareKey.UserCarRoleId))
            {
                return(FailedResult("User already has permissions to this car", 400));
            }

            var userCar = new UserCar {
                UserCarRoleId = shareKey.UserCarRoleId, UserId = userId, CarId = shareKey.CarId
            };

            if (!await _userCarRepository.CreateUserCarAsync(userCar))
            {
                return(FailedResult("Something went wrong!", 500));
            }

            if (!await MakeShareKeyUsed(shareKey))
            {
                return(FailedResult("Something went wrong!", 500));
            }

            var response = new UseShareKeyResponse {
                Success = true, CarId = shareKey.CarId
            };

            return(SuccessResult(response, 200));
        }
        public void EditCar_Must_Throw_Exception_When_Car_Not_Found()
        {
            //Arrange
            var userId = "1";
            var dto    = new AddOrEditUserCarDto
            {
                Id = 1
            };

            var validationResult = new ValidationResult("test");
            var userCar          = new UserCar
            {
                User = new UserProfile
                {
                    ApplicationUser = new ApplicationUser
                    {
                        Id = "another"
                    }
                }
            };

            _userManagerMock.Setup(act => act.IsUserInRegularRole(userId));
            _validationManagerMock.Setup(act => act.ValidateUserCarDto(dto)).Returns(validationResult);

            var userCarRepository = new Mock <IUserCarRepository>();

            userCarRepository.Setup(act => act.Get(dto.Id.Value)).Returns(userCar);
            _unitOfWorkMock.Setup(act => act.Repository <IUserCarRepository>()).Returns(userCarRepository.Object);

            //Act
            var exception = Assert.Throws <BusinessFaultException>(() => _manager.EditCar(dto, userId));

            //Assert
            Assert.AreEqual(BusinessLogicExceptionResources.CarDoesNotBelongToUser, exception.Message);
            _validationManagerMock.Verify(act => act.ValidateUserCarDto(dto), Times.Once);
            userCarRepository.Verify(act => act.Get(dto.Id.Value), Times.Once);
            _unitOfWorkMock.Verify(act => act.Repository <IUserCarRepository>(), Times.Once);
        }
Пример #14
0
        public IActionResult getUserName([FromBody] string name)
        {
            if (!String.IsNullOrEmpty(name))
            {
                var userParking = _dataContext.users.FirstOrDefault(u => u.Name == name);
                var carParking  = _dataContext.cars.FirstOrDefault(c => c.IdCar == userParking.Id);
                var userWithCar = new UserCar
                {
                    IdUserCar = userParking.Id,
                    user      = userParking,
                    car       = carParking
                };

                if (userWithCar == null)
                {
                    return(NotFound());
                }

                return(Ok(userWithCar));
            }

            return(NoContent());
        }
Пример #15
0
        public async Task <ServiceResult> CreateCarAsync(Guid userId, Car car)
        {
            if (car.MainName == null)
            {
                GenerateMainName(car);
            }

            if (!await _carRepository.CreateCarAsync(car))
            {
                return(FailResult(400, "Couldn't create a car"));
            }

            var userCar = new UserCar {
                UserId = userId, CarId = car.CarId, UserCarRoleId = "owner"
            };

            if (!await _userCarRepository.CreateUserCarAsync(userCar))
            {
                return(FailResult(400, "Couldn't create a car"));
            }

            return(SuccessResult(201, _mapper.Map <CreateCarResponse>(car)));
        }
Пример #16
0
        public async Task <IActionResult> AddCarToUser(UserCarViewModel userCarViewModel)
        {
            try
            {
                var user = await _context.Users.Include(x => x.UserCars).FirstOrDefaultAsync(m => m.Id == userCarViewModel.UserId);

                //var car = LicensePlateSearcher.CheckForCarInDatabase(userCarViewModel.CarBrand, userCarViewModel.CarMake);
                var newMake = userCarViewModel.CarMake.ToString().Split('-')[0].Trim().Replace(' ', ';');
                var car     = await _context.Cars.FirstOrDefaultAsync(c => c.Make == newMake);

                if (user != null && car != null)
                {
                    var userCar = new UserCar
                    {
                        User = user,
                        Car  = car
                    };

                    user.UserCars.Add(userCar);

                    _context.Add(userCar);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("CreatePath", "Path", user));
                }
                else
                {
                    throw new Exception("NULL");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(RedirectToAction("CreatePath", "Path"));
        }
Пример #17
0
        public async Task <ActionResult> PostUserWithCar([FromBody] UserCar userCar)
        {
            if (userCar != null)
            {
                User user = new User
                {
                    Name      = userCar.user.Name,
                    Surname   = userCar.user.Surname,
                    Email     = userCar.user.Email,
                    Telephone = userCar.user.Telephone
                };
                Car car = new Car
                {
                    Model        = userCar.car.Model,
                    LicencePlate = userCar.car.LicencePlate
                };

                UserCar userCarData = new UserCar {
                    IdUserCar = user.Id,
                    car       = car,
                    user      = user
                };
                _dataContext.users.Add(user);
                _dataContext.cars.Add(car);
                _dataContext.userscars.Add(userCarData);

                await _dataContext.SaveChangesAsync();

                //return CreatedAtAction("user", new { id = user.Id }, user);
                return(Ok());
            }
            else
            {
                return(StatusCode(400));
            }
        }
Пример #18
0
 public static void Unassign(this UserCar car)
 {
     car.Active          = false;
     car.EndOfAssignment = DateTime.UtcNow;
 }
Пример #19
0
        public async Task <bool> CreateUserCarAsync(UserCar userCar)
        {
            await _context.UserCars.AddAsync(userCar);

            return(await SaveChangesAsync());
        }
Пример #20
0
        public IActionResult getUserEmail([FromBody] string email)
        {
            if (!String.IsNullOrEmpty(email))
            {
                var userParking = _dataContext.users.FirstOrDefault(u => u.Email == email);
                if (userParking != null)
                {
                    var carParking = _dataContext.cars.FirstOrDefault(c => c.IdCar == userParking.Id);

                    var userWithCar = new UserCar
                    {
                        IdUserCar = userParking.Id,
                        user      = userParking,
                        car       = carParking
                    };

                    if (userWithCar == null)
                    {
                        return(NotFound());
                    }

                    _dataContext.users.Add(userParking);
                    _dataContext.cars.Add(carParking);
                    _dataContext.userscars.Add(userWithCar);

                    _dataContext.SaveChangesAsync();

                    return(Ok(userWithCar));
                }
                else
                {
                    var userParkingNew = new User {
                        Name      = "",
                        Surname   = "",
                        Email     = email,
                        Id        = 1,
                        Telephone = ""
                    };
                    var carParkingNew = new Car {
                        IdCar        = 1,
                        LicencePlate = "",
                        Model        = ""
                    };
                    var userWithCarNew = new UserCar {
                        IdUserCar = 1,
                        car       = carParkingNew,
                        user      = userParkingNew
                    };

                    _dataContext.users.Add(userParkingNew);
                    _dataContext.cars.Add(carParkingNew);
                    _dataContext.userscars.Add(userWithCarNew);

                    _dataContext.SaveChangesAsync();

                    return(Ok(userWithCarNew));
                }
            }

            return(NoContent());
        }
Пример #21
0
 public async Task <bool> DeleteUserCarAsync(UserCar userCar)
 {
     _context.UserCars.Remove(userCar);
     return(await SaveChangesAsync());
 }
Пример #22
0
        public async Task GetRelatedEntitiesCountShouldReturnCorrectValues()
        {
            var options = new DbContextOptionsBuilder <NeedForCarsDbContext>()
                          .UseInMemoryDatabase("RelatedEntitiesDb_models")
                          .Options;

            var context = new NeedForCarsDbContext(options);

            var makesService  = new MakesService(context);
            var modelsService = new ModelsService(context, makesService);

            var make = new Make
            {
                Name        = "Make",
                Description = "Desc"
            };
            await context.Makes.AddAsync(make);

            var model = new Model
            {
                MakeId = make.Id,
                Name   = "Model1",
            };
            await context.Models.AddAsync(model);

            var generation = new Generation
            {
                ModelId = model.Id,
                Name    = "Model1"
            };
            await context.Generations.AddAsync(generation);

            var engine = new Engine
            {
                Name     = "engine",
                MaxHP    = 100,
                FuelType = Models.Enums.FuelType.Diesel,
                Creator  = "creator"
            };
            await context.Engines.AddAsync(engine);

            var car = new Car
            {
                GenerationId = generation.Id,
                EngineId     = engine.Id,
                Transmission = Models.Enums.Transmission.Automatic,
                DriveWheel   = Models.Enums.DriveWheel.AllWheelDrive,
                BeginningOfProductionYear  = 2000,
                BeginningOfProductionMonth = 1
            };
            await context.Cars.AddAsync(car);

            var user = new NeedForCarsUser
            {
                Email        = "*****@*****.**",
                UserName     = "******",
                PasswordHash = "HASHEDPASSWORD",
                FirstName    = "First",
                LastName     = "Last",
                PhoneNumber  = "1234567890"
            };
            await context.Users.AddAsync(user);

            var userCar = new UserCar
            {
                OwnerId             = user.Id,
                CarId               = car.Id,
                Color               = "color",
                ProductionDateYear  = 2000,
                ProductionDateMonth = 1,
                Mileage             = 0
            };
            await context.UserCars.AddAsync(userCar);

            await context.SaveChangesAsync();

            modelsService.GetRelatedEntitiesCount(model, out int generations, out int cars, out int userCars);

            Assert.True(generations == 1 && cars == 1 && userCars == 1);
        }
Пример #23
0
 public static void Remove(this UserCar car)
 {
     car.Deleted         = true;
     car.Active          = false;
     car.EndOfAssignment = DateTime.UtcNow;
 }
Пример #24
0
 public static void CreateAndAddHistory(this DbSet <History> histories, User user, ActionType actionType, UserCar car = null)
 {
     histories.Add(new History()
     {
         User = user, ActionType = actionType, Date = DateTime.Now, Car = car
     });
 }
        public async Task GetAllPublicShouldOnlyReturnPublicUserCars()
        {
            var options = new DbContextOptionsBuilder <NeedForCarsDbContext>()
                          .UseInMemoryDatabase("GetAllPublicUserCarDb")
                          .Options;

            var context = new NeedForCarsDbContext(options);

            var userCarsService = new UserCarsService(context);

            var make = new Make
            {
                Name        = "Make",
                Description = "Desc"
            };

            await context.Makes.AddAsync(make);

            await context.SaveChangesAsync();

            var model = new Model
            {
                MakeId = make.Id,
                Name   = "Model"
            };

            await context.Models.AddAsync(model);

            await context.SaveChangesAsync();

            var generation = new Generation
            {
                ModelId     = model.Id,
                BodyType    = Models.Enums.BodyType.Convertible,
                Name        = "Name",
                Seats       = 5,
                Description = "Desc"
            };

            await context.Generations.AddAsync(generation);

            await context.SaveChangesAsync();

            var engine = new Engine
            {
                Name     = "Name1",
                FuelType = Models.Enums.FuelType.Diesel,
                MaxHP    = 100,
                Creator  = "Creator"
            };

            await context.AddAsync(engine);

            await context.SaveChangesAsync();

            var car = new Car
            {
                GenerationId = generation.Id,
                EngineId     = engine.Id,
                Transmission = Models.Enums.Transmission.Automatic,
                DriveWheel   = Models.Enums.DriveWheel.AllWheelDrive,
                BeginningOfProductionYear  = 2000,
                BeginningOfProductionMonth = 1
            };

            await context.Cars.AddAsync(car);

            await context.SaveChangesAsync();

            var user = new NeedForCarsUser
            {
                Email        = "*****@*****.**",
                UserName     = "******",
                PasswordHash = "HASHEDPASSWORD",
                FirstName    = "First",
                LastName     = "Last",
                PhoneNumber  = "1234567890"
            };
            await context.Users.AddAsync(user);

            await context.SaveChangesAsync();

            var userCar1 = new UserCar
            {
                OwnerId             = user.Id,
                CarId               = car.Id,
                Color               = "color",
                ProductionDateYear  = 2000,
                ProductionDateMonth = 1,
                Mileage             = 0,
                IsPublic            = true
            };
            var userCar2 = new UserCar
            {
                OwnerId             = user.Id,
                CarId               = car.Id,
                Color               = "color",
                ProductionDateYear  = 2000,
                ProductionDateMonth = 1,
                Mileage             = 0,
                IsPublic            = false
            };

            await context.UserCars.AddAsync(userCar1);

            await context.UserCars.AddAsync(userCar2);

            await context.SaveChangesAsync();

            var result = await userCarsService.GetAllPublic().CountAsync();

            Assert.Equal(1, result);
        }
Пример #26
0
        public async Task UpdateAsync(UserCar userCar)
        {
            this.context.Update(userCar);

            await this.context.SaveChangesAsync();
        }