Ejemplo n.º 1
0
        public async Task <IActionResult> CreateBranchAsync([FromBody] BranchModelRq model)
        {
            if (!ModelState.IsValid)
            {
                Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
                foreach (var entry in ModelState.Values)
                {
                    foreach (var error in entry.Errors)
                    {
                        modelErrors.Add(error);
                    }
                }
                return(BadRequest(modelErrors));
            }
            var issuer = GetCurrentUserIdentity <int>();

            try
            {
                if (await _branchService.CheckCodeExistsAsync(model.Code))
                {
                    return(BadRequest("Code Exists"));
                }
                return(Ok(await _branchService.CreateBranchAsync(model, issuer)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task <IActionResult> CreateBranch(CreateBranchModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Geçersiz veri"));
            }

            // Yeni bir şube tanımlar.
            var branch = new Branch
            {
                DateCreated = DateTime.Now,
                FirmId      = _currentFirm.Id,
                IsActive    = true,
                Name        = model.Name,
                CityId      = Convert.ToInt32(model.City.Decrypt())
            };

            var branchId = await _branchService.CreateBranchAsync(branch);

            // Tanımlanan şubeye ait bir yönetici kullanıcı tanımlar.
            var user = new ApplicationUser
            {
                DateCreated          = DateTime.Now,
                IsActive             = true,
                Email                = model.Email,
                EmailConfirmed       = true,
                BranchId             = branchId,
                Name                 = model.Name,
                NormalizedEmail      = model.Email,
                NormalizedUserName   = model.Email,
                UserName             = model.Email,
                PhoneNumber          = model.PhoneNumber,
                PhoneNumberConfirmed = true
            };

            await _userService.CreateUserAsync(user, model.Password, "Branch");

            _logger.LogInformation(string.Format("#{0} firması {1} şubesi ve {2} şube kullanıcısı oluşturdu.", _currentUser.Name, branch.Name, user.Name));

            return(Ok("Şube kaydedildi"));
        }
        public async Task <IActionResult> CreateBranchAsync(
            [FromQuery] int organisationId,
            [FromBody] CreateBranchRequestDto createBranchRequestDto,
            CancellationToken token = default)
        {
            try
            {
                var validationResult = await _createBranchRequestDtoValidator.ValidateAsync(createBranchRequestDto, token);

                if (!validationResult.IsValid)
                {
                    return(new BadRequestObjectResult(validationResult.Errors.ToValidationErrors()));
                }
                var branchServiceObject = Mapper.Map <BranchServiceObject>(createBranchRequestDto);
                branchServiceObject.OrganisationId = organisationId;
                var serviceResponse = await _branchService.CreateBranchAsync(branchServiceObject, token);

                return(new CreatedResult(string.Empty, Mapper.Map <CreateBranchResponseDto>(serviceResponse)));
            }
            catch (Exception)
            {
                return(new BadRequestResult());
            }
        }
Ejemplo n.º 4
0
        public async Task CreateAsync(BranchCreateCommand command)
        {
            string decodedUrl = StoreUrlEncoder.Decode(command.Url);

            await _service.CreateBranchAsync(decodedUrl, command.Name, command.SourceName);
        }