示例#1
0
        public IActionResult UpdateDistribuidor([FromBody] Model.Distribuidor instance)
        {
            if (instance == null || instance == Model.Distribuidor.Empty)
            {
                return(BadRequest());
            }

            var handler = new HttpClientHandler {
                Credentials = new NetworkCredential(DataAccess.IBMDataAccess.USER, DataAccess.IBMDataAccess.PASSWORD)
            };

            using (var client = DataAccess.IBMDataAccess.CreateHttpClient(handler, DataAccess.IBMDataAccess.USER, TABELA_DISTRIBUIDOR))
            {
                var updateResponse = DataAccess.IBMDataAccess.Update <Model.Distribuidor>(client, instance._id, instance);

                if (updateResponse.StatusCode == HttpStatusCode.Created)
                {
                    var revNew = DataAccess.IBMDataAccess.GetString("rev", updateResponse);

                    instance._rev = revNew;

                    return(Created(client.BaseAddress, instance));
                }
                else
                {
                    return(BadRequest());
                }
            }
        }
示例#2
0
        public IActionResult AddDistribuidor([FromBody] Model.Distribuidor instance)
        {
            if (instance == null || instance == Model.Distribuidor.Empty)
            {
                return(BadRequest());
            }

            var handler = new HttpClientHandler {
                Credentials = new NetworkCredential(DataAccess.IBMDataAccess.USER, DataAccess.IBMDataAccess.PASSWORD)
            };

            using (var client = DataAccess.IBMDataAccess.CreateHttpClient(handler, DataAccess.IBMDataAccess.USER, TABELA_DISTRIBUIDOR))
            {
                var creationResponse = DataAccess.IBMDataAccess.Create <Model.Distribuidor>(client, instance);

                if (creationResponse.StatusCode == HttpStatusCode.Created)
                {
                    var id = DataAccess.IBMDataAccess.GetString("id", creationResponse);

                    var readResponse = DataAccess.IBMDataAccess.Read(client, id);

                    var data = DataAccess.IBMDataAccess.GetObjectModel <Model.Distribuidor>(readResponse);

                    return(Created(client.BaseAddress, data));
                }
                else
                {
                    return(BadRequest());
                }
            }
        }