コード例 #1
0
        public async Task <IResult> AddAsync(CustomerAddDto customerCreateDto)
        {
            var lastUserInsertIdResult = await _userService.GetLastInsertUserAsync();

            if (!lastUserInsertIdResult.Success)
            {
                return(lastUserInsertIdResult);
            }

            var createToCustomer = new Customer()
            {
                CompanyName = customerCreateDto.CompanyName,
                UserId      = lastUserInsertIdResult.Data.Id
            };

            bool addResult = await _customerDal.AddAsync(createToCustomer);

            if (addResult == true)
            {
                return(new SuccessResult(Messages.CustomerAdded));
            }
            else
            {
                return(new ErrorResult(Messages.CustomerNotAdded));
            }
        }
コード例 #2
0
        public IResult Add(CustomerAddDto customerAddDto)
        {
            //mapping
            Customer customer = _mapper.Map <Customer>(customerAddDto);

            _customerDal.Add(customer);
            return(new SuccessResult(Messages.CustomerAdded));
        }
コード例 #3
0
        public IActionResult Add(CustomerAddDto customerAddDto)
        {
            var result = _customerService.Add(customerAddDto);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
コード例 #4
0
        public async Task <IActionResult> AddAsync(CustomerAddDto customerCreateDto)
        {
            var result = await _customerService.AddAsync(customerCreateDto);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
コード例 #5
0
        public async Task <IActionResult> Create(CustomerAddDto model)
        {
            if (ModelState.IsValid)
            {
                Customer customer = _mapper.Map <Customer>(model);

                await _customerManager.AddCustomer(customer);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(model));
            }
        }
コード例 #6
0
        public async Task <IActionResult> CreateCustomer(CustomerAddDto customerAdd)
        {
            if (customerAdd == null)
            {
                return(BadRequest());
            }

            var customer = mapper.Map <Customer>(customerAdd);

            repository.AddCustomer(customer);
            await repository.SaveChangeAsync();

            var customerDto = mapper.Map <CustomerDto>(customer);

            return(CreatedAtRoute(
                       nameof(GetCustomer),
                       new { customerId = customerDto.Id }, customerDto));
        }
コード例 #7
0
        public async Task <IResult> Insert(CustomerAddDto customerAddDto)
        {
            try
            {
                CustomerEntity customer = Mapper.Map <CustomerEntity>(customerAddDto);
                await UnitOfWork.Customer.AddAsync(customer);

                await UnitOfWork.SaveAsync();

                var result = Mapper.Map <CustomerEntity, CustomerAddDto>(customer);
                return(new Result(ResultStatus.Success, $"{result.CustomerName} eklendi"));
            }
            catch (Exception ex)
            {
                //Logger.Log(LogLevel.Error, ex, ex.Message);
                throw;
            }
        }
コード例 #8
0
        public async Task <ActionResult <ApiResponse <Customer> > > Add(CustomerAddDto dto)
        {
            try
            {
                var isVerified = await _verificationService.VerifyCode(dto.PhoneNo, dto.VerificationCode);

                if (!isVerified)
                {
                    throw new Exception("Invalid verification code!");
                }
                var customer        = _mapper.Map <Customer>(dto);
                var createdCustomer = await _customerService.AddCustomer(customer);

                return(createdCustomer.CreateSuccessResponse("Customer created successfully!"));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.CreateErrorResponse()));
            }
        }
コード例 #9
0
        public async Task <IResult> Insert([FromBody] CustomerAddDto customerAddDto)
        {
            IResult result = await customerOperationManager.Insert(customerAddDto);

            return(result);
        }