Exemple #1
0
        public async Task <APIResponse> CreateBranch(CreateBranchRequest request)
        {
            try
            {
                var vendorclient = httpClientFactory.CreateClient(VendorServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await vendorclient.PostAsync(servicesConfig.Vendor + VendorServiceOperation.CreateBranch(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var branch = JsonConvert.DeserializeObject <List <BranchServiceResponseId> >(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(branch, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateBranch()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
Exemple #2
0
        internal CreateBranchResponse CreateBranch(CreateBranchRequest request)
        {
            var marshaller   = new CreateBranchRequestMarshaller();
            var unmarshaller = CreateBranchResponseUnmarshaller.Instance;

            return(Invoke <CreateBranchRequest, CreateBranchResponse>(request, marshaller, unmarshaller));
        }
        public async Task <IActionResult> CreateBranch([FromBody] CreateBranchRequest request)
        {
            var createBranchCommand = new CreateBranchCommand(request);
            var result = await mediator.Send(createBranchCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
        /// <summary>
        /// Add or Edit an existing branch
        /// </summary>
        /// <param name="branchId"></param>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <Response> AddOrEditBranchAsync(int branchId, CreateBranchRequest request, CancellationToken cancellationToken = default)
        {
            var responseModel = new Response();

            if (await BranchExists(request.Address.CountryId, request.Address.CityId, request.Name))
            {
                responseModel.AddError(ExceptionCreator.CreateBadRequestError("branch", $"branch name: {request.Name} already exists"));
                return(responseModel);
            }

            if (branchId != 0)
            {
                var branch = await _branchRepo.FindByIdAsync(branchId);

                if (branch != null)
                {
                    branch.Name           = request.Name;
                    branch.Code           = request.Code;
                    branch.Address        = request.Address;
                    branch.LastModifiedBy = _httpContextAccessor.HttpContext.User.Identity.Name;
                    branch.LastModifiedOn = DateTime.UtcNow;

                    await _branchRepo.UpdateAsync(_dbContext, branch);
                }
                else
                {
                    responseModel.AddError(ExceptionCreator.CreateNotFoundError(nameof(branch), $"branch of Id: {branchId} not found"));
                    return(responseModel);
                }
            }
            else
            {
                var newAddress = CreateAddress(request);
                var newBranch  = CreateBranch(request);

                var dbContextTransaction = await _dbContext.Database.BeginTransactionAsync(cancellationToken);

                using (dbContextTransaction)
                {
                    try
                    {
                        await _addressRepo.AddAsync(newAddress, _dbContext);

                        newBranch.AddressId = newAddress.Id;

                        await _branchRepo.AddAsync(_dbContext, newBranch);

                        await dbContextTransaction.CommitAsync(cancellationToken);
                    }
                    catch (Exception ex)
                    {
                        await dbContextTransaction.RollbackAsync(cancellationToken);

                        responseModel.AddError(ExceptionCreator.CreateInternalServerError(ex.ToString()));
                    }
                }
            }

            return(responseModel);
        }
Exemple #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateBranch operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateBranch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <CreateBranchResponse> CreateBranchAsync(CreateBranchRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new CreateBranchRequestMarshaller();
            var unmarshaller = CreateBranchResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateBranchRequest, CreateBranchResponse>(request, marshaller,
                                                                           unmarshaller, cancellationToken));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateBranch operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateBranch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/amplify-2017-07-25/CreateBranch">REST API Reference for CreateBranch Operation</seealso>
        public virtual Task <CreateBranchResponse> CreateBranchAsync(CreateBranchRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = CreateBranchRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateBranchResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateBranchResponse>(request, options, cancellationToken));
        }
        internal virtual CreateBranchResponse CreateBranch(CreateBranchRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = CreateBranchRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateBranchResponseUnmarshaller.Instance;

            return(Invoke <CreateBranchResponse>(request, options));
        }
        private Branch CreateBranch(CreateBranchRequest request)
        {
            if (request != null)
            {
                return(new Branch()
                {
                    Name = request.Name,
                    Code = request.Code,
                    Phone = request.Phone,
                    Address = request.Address,
                    CreatedBy = _httpContextAccessor.HttpContext.User.Identity.Name
                });
            }

            return(null);
        }
        public CreateBranchResponse CreateBranch(CreateBranchRequest request)
        {
            var response = new CreateBranchResponse();
            var entity   = CommonLogic.SetMapping <CreateBranchRequest, Branch>(request);

            try
            {
                _context.Add(entity);
                _context.SaveChanges();
                response.IsSuccess = true;
            }
            catch
            {
                throw new Exception();
            }
            return(response);
        }
        private Address CreateAddress(CreateBranchRequest request)
        {
            if (request != null)
            {
                var address = request.Address;

                return(new Address()
                {
                    Name = address.Name,
                    DistrictId = address.DistrictId,
                    CityId = address.CityId,
                    CountryId = address.CountryId,
                    Street = address?.Street,
                    PostalCode = address?.PostalCode
                });
            }

            return(null);
        }
Exemple #11
0
        public async Task <ActionResult <CreateBranchResponse> > Create([FromBody] CreateBranchRequest request)
        {
            var response = _mediator.Send(request);

            return(CreatedAtAction(nameof(Get), new { Id = response.Id }, response));
        }
 public async Task <Branch> CreateAsync(CreateBranchRequest request) =>
 await _httpFacade.Post <Branch>($"projects/{request.ProjectId}/repository/branches", request);
        public async Task <IActionResult> CreateBranch([FromBody] CreateBranchRequest request)
        {
            var result = await branchService.CreateBranch(request);

            return(StatusCode((int)result.Code, result.Value));
        }
Exemple #14
0
        public async Task <IActionResult> AddOrEditBranchAsync([FromRoute] int branchId, [FromBody] CreateBranchRequest request,
                                                               CancellationToken cancellationToken = default)
        {
            try
            {
                var apiResponse = await _branchService.AddOrEditBranchAsync(branchId, request, cancellationToken);

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


                else if (apiResponse.Errors[0].Code == StatusCodes.Status404NotFound)
                {
                    return(NotFound(apiResponse));
                }


                return(BadRequest(apiResponse));
            }

            catch (Exception exception)
            {
                return(_actionResultMapper.Map(exception));
            }
        }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateServiceQuestionCommand"/> class.
 /// </summary>
 /// <param name="servicequestionrequest">The servicequestionrequest.</param>
 public CreateBranchCommand(CreateBranchRequest branchRequest)
 {
     BranchRequest = branchRequest;
 }
Exemple #16
0
        public IActionResult CreateBranch(CreateBranchRequest request)
        {
            var response = _service.CreateBranch(request);

            return(Ok(response));
        }