Пример #1
0
        public ActionResult AddTiedHouseConnection([FromBody] ViewModels.TiedHouseConnection item, string accountId)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var tiedHouse = new MicrosoftDynamicsCRMadoxioTiedhouseconnection();

            // copy values over from the data provided
            tiedHouse.CopyValues(item);
            tiedHouse.AccountODataBind = _dynamicsClient.GetEntityURI("accounts", accountId);
            try
            {
                tiedHouse = _dynamicsClient.Tiedhouseconnections.Create(tiedHouse);
            }
            catch (HttpOperationException httpOperationException)
            {
                tiedHouse.AdoxioTiedhouseconnectionid = _dynamicsClient.GetCreatedRecord(httpOperationException, null);
                if (string.IsNullOrEmpty(tiedHouse.AdoxioTiedhouseconnectionid))
                {
                    _logger.LogError(httpOperationException, "Error creating tiedhouse connection ");
                    throw new Exception("Error creating tiedhouse connection");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error creating tiedhouse connection");
                throw new Exception("Error creating tiedhouse connection");
            }

            return(new JsonResult(tiedHouse.ToViewModel()));
        }
        public ActionResult AddTiedHouseConnection([FromBody] ViewModels.TiedHouseConnection item, string accountId)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var tiedHouse = new MicrosoftDynamicsCRMadoxioTiedhouseconnection();

            // copy values over from the data provided
            tiedHouse.CopyValues(item);
            tiedHouse.AccountODataBind = _dynamicsClient.GetEntityURI("accounts", accountId);
            try
            {
                tiedHouse = _dynamicsClient.Tiedhouseconnections.Create(tiedHouse);
            }
            catch (OdataerrorException odee)
            {
                tiedHouse.AdoxioTiedhouseconnectionid = _dynamicsClient.GetCreatedRecord(odee, null);
                if (string.IsNullOrEmpty(tiedHouse.AdoxioTiedhouseconnectionid))
                {
                    _logger.LogError("Error creating tiedhouse connection");
                    _logger.LogError("Request:");
                    _logger.LogError(odee.Request.Content);
                    _logger.LogError("Response:");
                    _logger.LogError(odee.Response.Content);
                    throw new Exception("Unable to update tied house connections");
                }
            }

            return(Json(tiedHouse.ToViewModel()));
        }
Пример #3
0
        public async Task <IActionResult> UpdateTiedHouse([FromBody] ViewModels.TiedHouseConnection item, string id)
        {
            if (item == null || id != item.id)
            {
                return(BadRequest());
            }

            // get the legal entity.
            Guid tiedHouseId = new Guid(id);

            MicrosoftDynamicsCRMadoxioTiedhouseconnection res = await _dynamicsClient.GetTiedHouseConnectionById(tiedHouseId);

            if (res == null)
            {
                return(new NotFoundResult());
            }

            // we are doing a patch, so wipe out the record.
            var tiedHouse = new MicrosoftDynamicsCRMadoxioTiedhouseconnection();

            // copy values over from the data provided
            tiedHouse.CopyValues(item);

            try
            {
                await _dynamicsClient.AdoxioTiedhouseconnections.UpdateAsync(tiedHouseId.ToString(), tiedHouse);
            }
            catch (OdataerrorException odee)
            {
                _logger.LogError("Error updating tied house connections");
                _logger.LogError("Request:");
                _logger.LogError(odee.Request.Content);
                _logger.LogError("Response:");
                _logger.LogError(odee.Response.Content);
                throw new Exception("Unable to update tied house connections");
            }


            return(Json(tiedHouse.ToViewModel()));
        }