コード例 #1
0
        public ApiResponse <long> CreateGarage(GarageAndUserDto garage)
        {
            if (garage == null)
            {
                return(new ApiResponse <long> {
                    ResponseStatusCode = RestStatusCode.NotFound
                });
            }

            var userExist = _uow.UserRepository.GetAll(false).FirstOrDefault(x => x.Email == garage.Email);

            if (userExist != null)
            {
                return new ApiResponse <long> {
                           ResponseStatusCode = RestStatusCode.AccountCreationFailed
                }
            }
            ;

            long gId;

            using (_uow.BeginTransaction())
            {
                var createGarage = new Garage()
                {
                    Name  = garage.GarageName,
                    Email = garage.Email
                };

                var garageId = _uow.GarageRepository.Create(createGarage, false);
                gId = garageId;

                createGarage.GarageContextId = garageId;
                _uow.GarageRepository.Update(createGarage, false);


                var createPerson = new Person()
                {
                    Name            = garage.Name,
                    LastName        = garage.LastName,
                    Email           = garage.Email,
                    GarageContextId = garageId,
                    Active          = true
                };
                createPerson.PersonType = PersonTypeEnum.Boss;

                personId = _uow.PersonRepository.Create(createPerson, false);


                byte[] passwordHash, passwordSalt;
                CreatePasswordHash(garage.Password, out passwordHash, out passwordSalt);

                var userToRepo = new User()
                {
                    Email           = garage.Email,
                    PasswordHash    = passwordHash,
                    PasswordSalt    = passwordSalt,
                    PersonId        = personId,
                    GarageContextId = garageId
                };

                _uow.UserRepository.Create(userToRepo, false);

                _uow.CommitTransaction();
            }

            return(new ApiResponse <long>
            {
                ResponseResult = gId,
                ResponseStatusCode = RestStatusCode.OK
            });
        }
コード例 #2
0
 public async Task <IActionResult> CreateGarage(GarageAndUserDto garage)
 {
     return(await Task.Run(() => CallApi(() => _garageService.CreateGarage(garage))));
 }