FarmerSummary Map(tblFarmers farmer)
 {
     return new FarmerSummary
                {
                    Id = farmer.Id,
                    FactoryWSUrl = farmer.FactoryUrl,
                    Code = farmer.Code,
                    DateCreated = farmer.IM_DateCreated,
                    DateUpdated = farmer.IM_DateLastUpdated,
                    FactoryCode = farmer.FactoryCode,
                    FactoryId = farmer.FactoryId,
                    FullName = farmer.FullName,
                    IsActive = farmer.IM_Status
                };
 }
        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;
        }