Exemplo n.º 1
0
        public async Task<FarmerSummary> GetFarmerSummary(FarmerSummary farmer)
        {
            string factoryUrl = farmer.FactoryWSUrl;
            if (!factoryUrl.EndsWith("/")) factoryUrl = factoryUrl + "/";
            string url = string.Format("api/distributorservices/getfarmersummary" + "?farmerId={0}", farmer.Id);
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(farmer.FactoryWSUrl);
            var response = await client.GetAsync(url);

            var cummWeight = await response.Content.ReadAsAsync<FarmerSummary>();

            return cummWeight;
        }
        public bool RegisterFarmer(FarmerSummary farmer)
        {
            tblFarmers tfarmer = _ctx.tblFarmers.FirstOrDefault(n => n.Id == farmer.Id);
            if (tfarmer == null)
            {
                tfarmer = new tblFarmers()
                              {
                                  IM_Status = true,
                                  Id = farmer.Id,
                                  IM_DateCreated = DateTime.Now
                              };
                _ctx.tblFarmers.Add(tfarmer);
            }
            tfarmer.FullName = farmer.FullName.Trim();
            tfarmer.FactoryCode = farmer.FactoryCode.Trim();
            tfarmer.Code = farmer.Code.Trim();
            tfarmer.FactoryId = farmer.FactoryId;
            tfarmer.FactoryUrl = farmer.FactoryWSUrl.Trim();
            tfarmer.IM_DateLastUpdated = DateTime.Now;

            _ctx.SaveChanges();
            return true;
        }