Exemple #1
0
        public async Task <ActionResult <MerchantMBE> > AddMerchant([FromBody] NewMerchantMBE newMerchant)
        {
            // validate request data
            if (string.IsNullOrEmpty(newMerchant.MerchantName))
            {
                return(BadRequest(new ArgumentNullException(nameof(newMerchant.MerchantName), @"You must supply a non blank value for the Merchant Name.")));
            }
            // validate the input params

            /*if (!Uri.IsWellFormedUriString(newMerchant.MerchantUrl.ToString(), UriKind.Absolute))
             * {
             *
             *  return BadRequest(new ArgumentException(nameof(newMerchant.MerchantUrl), @"The merchant url is incorrect. Make sure the url has https:// or http://"));
             * }*/

            var merchant = new MerchantMBE
            {
                MerchantGuid   = GeneralConstants.MERCHANT_1_GUID,
                MerchantName   = newMerchant.MerchantName,
                MerchantUrl    = new Uri("https://www.testmerchant.com"),
                IsSupportsTips = newMerchant.IsSupportsTips
            };

            await Task.Delay(100);

            return(CreatedAtAction(nameof(GetMerchant), new { merchantGuid = merchant.MerchantGuid }, merchant));
        }
Exemple #2
0
        public async Task <ActionResult> UpdateMerchant(Guid merchantGuid, [FromBody] NewMerchantMBE updatedMerchant)
        {
            // validate the input params
            if (merchantGuid != GeneralConstants.MERCHANT_1_GUID)
            {
                return(NotFound($"Merchant with ID: {merchantGuid} not found"));
            }
            // validate the input params

            /*if (!Uri.IsWellFormedUriString(updatedMerchant.MerchantUrl.ToString(), UriKind.Absolute))
             * {
             *
             *  return BadRequest(new ArgumentException(nameof(updatedMerchant.MerchantUrl), @"The merchant url is incorrect. Make sure the url has https:// or http://"));
             * }*/

            await Task.Delay(100);

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <MerchantMBE> > AddMerchant([FromBody] NewMerchantMBE newMerchant)
        {
            //trims merchant name so that it doesn't have trailing characters
            newMerchant.MerchantName = newMerchant.MerchantName.Trim();

            // validate the input params
            //if (!Uri.IsWellFormedUriString(newMerchant.MerchantUrl.ToString(), UriKind.Absolute))
            //{
            //    return BadRequest(new ArgumentException(nameof(newMerchant.MerchantUrl), @"The merchant url is incorrect. Make sure the url has https://"));
            //}

            try
            {
                // store the new merchant
                var newDBMerchant = new MerchantDBE()
                {
                    MerchantName   = newMerchant.MerchantName,
                    IsSupportsTips = newMerchant.IsSupportsTips,
                    MerchantUrl    = (Uri.IsWellFormedUriString(newMerchant.MerchantUrl.ToString(), UriKind.Absolute))
                                    ? newMerchant.MerchantUrl
                                    : new Uri("https://www.testmerchant.com")
                };

                await _dbContext.InsertMerchantAsync(newDBMerchant);

                // convert DB entity to the public entity type
                var merchant = (MerchantMBE)newDBMerchant;

                // return the response
                return(CreatedAtAction(nameof(GetMerchant), new { merchantGuid = merchant.MerchantGuid }, merchant));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApplicationException($"Error: [{ex.Message}] Failed trying to add merchant: [{newMerchant.MerchantName}]")));
            }
        }
Exemple #4
0
        public async Task <ActionResult> UpdateMerchant([FromRoute] Guid merchantGuid, [FromBody] NewMerchantMBE updatedMerchant)
        {
            //trims merchant name so that it doesn't have trailing characters
            updatedMerchant.MerchantName = updatedMerchant.MerchantName.Trim();

            // validate the input params

            /*if (!Uri.IsWellFormedUriString(updatedMerchant.MerchantUrl.ToString(), UriKind.Absolute))
             * {
             *
             *  return BadRequest(new ArgumentException(nameof(updatedMerchant.MerchantUrl), @"The merchant url is incorrect. Make sure the url has https://"));
             * }*/

            // query the DB
            var dbMerchant = await _dbContext.GetMerchantAsync(merchantGuid);

            // if we did not find a matching merchant
            if (dbMerchant == null)
            {
                return(NotFound($"MerchantGuid: [{merchantGuid}] not found"));
            }

            string exisitingDBMerchantName = dbMerchant.MerchantName;

            try
            {
                // save the updated merchant
                dbMerchant.MerchantName   = updatedMerchant.MerchantName;
                dbMerchant.IsSupportsTips = updatedMerchant.IsSupportsTips;
                dbMerchant.MerchantUrl    = (Uri.IsWellFormedUriString(updatedMerchant.MerchantUrl.ToString(), UriKind.Absolute))
                                            ? updatedMerchant.MerchantUrl
                                            : new Uri("https://www.testmerchant.com");

                await _dbContext.UpdateMerchantAsync(dbMerchant);
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApplicationException($"Error: [{ex.Message}] failed trying to update merchant: [{exisitingDBMerchantName}]")));
            }

            return(NoContent());
        }