public bool CreateAccount(Account userdata, out bool IsDuplicate)
        {
            bool result = default(bool);

            IsDuplicate = false;
            try
            {
                result = new RepositoryCreator().AccountRepository.CreateAccount(userdata, out IsDuplicate);

                if (result == true && userdata.UserId > default(int))
                {
                    var         connectionString = "AggieGlobal";
                    FarmManager fmanager         = new FarmManager(connectionString);
                    FarmDetail  fDetail          = new FarmDetail();
                    fDetail.FarmId              = default(int);
                    fDetail.FarmName            = "Farm_" + userdata.EmailId;
                    fDetail.FarmSize            = default(int);
                    fDetail.FarmSizeUnit        = string.Empty;
                    fDetail.FarmAddress         = string.Empty;
                    fDetail.FarmEstablishedDate = DateTime.Now;
                    userdata.FarmId             = fmanager.CreateUpdateFarm(fDetail);
                    if (userdata.FarmId > default(int))
                    {
                        fmanager.MapFarmByUserDetail(userdata.FarmId, userdata.UserId);
                    }
                    fmanager.Dispose();
                }
            }
            catch (Exception ex)
            {
                AggieGlobalLogManager.Fatal("AccountManager :: CreateAccount failed :: " + ex.Message);
            }
            return(result);
        }
        public FarmDetailResponse MapFarmByUserDetail(string FarmId)
        {
            bool res = default(bool);
            FarmDetailResponse resposne      = null;
            SessionData        sessionObject = null;
            int farmId = default(int);
            int userId = default(int);

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];
                    resposne      = new FarmDetailResponse();
                    if (string.IsNullOrEmpty(FarmId))
                    {
                        resposne.Error  = "Failed to process";
                        resposne.Status = ResponseStatus.Failed;
                        return(resposne);
                    }
                    else
                    {
                        farmId = Convert.ToInt32(EncryptionHelper.AesDecryption(FarmId, EncryptionKey.LOG));
                        userId = sessionObject._userId;
                    }


                    AggieGlobalLogManager.Info("FarmDetailsController :: MapFarmByUserDetail started ");
                    var connectionString = "AggieGlobal";

                    var repo = new FarmManager(connectionString);

                    res = repo.MapFarmByUserDetail(farmId, userId);
                    if (res == true)
                    {
                        resposne.Status = ResponseStatus.Successful;
                    }
                    else
                    {
                        resposne.Error  = "Failed to process data";
                        resposne.Status = ResponseStatus.Failed;
                    }
                    AggieGlobalLogManager.Info("FarmDetailsController :: MapFarmByUserDetail ended ");
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                resposne.Error  = "Failed to process";
                resposne.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("FarmManager :: MapFarmByUserDetail failed :: " + ex.Message);
            }
            return(resposne);
        }
        public IList <FarmDetailResponse> GetAllFarmsDetails()
        {
            bool ret = default(bool);
            IEnumerable <FarmDetail>   farmData     = null;
            IList <FarmDetailResponse> responsedata = new List <FarmDetailResponse>();

            try
            {
                AggieGlobalLogManager.Info("FarmDetailsController :: GetFarmsDetails started ");
                var connectionString = "AggieGlobal";
                var repo             = new FarmManager(connectionString);
                farmData = repo.GetFarmDetails(default(int));
                if (farmData != null && farmData.Count() > default(int))
                {
                    foreach (FarmDetail det in farmData)
                    {
                        FarmDetailResponse resdata = new FarmDetailResponse();
                        resdata.FarmId              = EncryptionHelper.AesEncryption(Convert.ToString(det.FarmId), EncryptionKey.LOG);
                        resdata.FarmName            = det.FarmName;
                        resdata.CoOpName            = det.CoOpName;
                        resdata.FarmAddress         = det.FarmAddress;
                        resdata.FarmEstablishedDate = det.FarmEstablishedDate;
                        resdata.FarmSize            = det.FarmSize;
                        resdata.FarmSizeUnit        = det.FarmSizeUnit;
                        resdata.Status              = ResponseStatus.Successful;
                        responsedata.Add(resdata);
                    }
                }
                else
                {
                    FarmDetailResponse resdata = new FarmDetailResponse();
                    resdata.Error  = "Failed to retreive data";
                    resdata.Status = ResponseStatus.Failed;
                    responsedata.Add(resdata);
                }
                repo.Dispose();
            }
            catch (Exception ex)
            {
                FarmDetailResponse resdata = new FarmDetailResponse();
                resdata.Error  = "Failed to retreive data";
                resdata.Status = ResponseStatus.Failed;
                responsedata.Add(resdata);

                AggieGlobalLogManager.Fatal("FarmDetailsController :: GetFarmsDetails failed :: " + ex.Message);
            }
            return(responsedata);
        }
        public FarmDetailResponse CreateUpdateFarm(FarmDetailResponse requestData)
        {
            int res = default(int);
            FarmDetailResponse responsedata = new FarmDetailResponse();

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];
                    AggieGlobalLogManager.Info("FarmDetailsController :: GetFarmsDetails started ");
                    var        connectionString = "AggieGlobal";
                    var        repo             = new FarmManager(connectionString);
                    FarmDetail response         = new FarmDetail();
                    response.FarmId              = string.IsNullOrEmpty(requestData.FarmId) == true ? default(int) : Convert.ToInt32(EncryptionHelper.AesDecryption(requestData.FarmId, EncryptionKey.LOG));;
                    response.FarmName            = responsedata.FarmName;
                    response.FarmSize            = requestData.FarmSize;
                    response.FarmSizeUnit        = requestData.FarmSizeUnit;
                    response.FarmAddress         = requestData.FarmAddress;
                    response.FarmEstablishedDate = requestData.FarmEstablishedDate;

                    res = repo.CreateUpdateFarm(response);

                    if (res > default(int))
                    {
                        requestData.FarmId  = (res == default(int) ? string.Empty : Convert.ToString(EncryptionHelper.AesEncryption(res.ToString(), EncryptionKey.LOG)));
                        responsedata.Status = ResponseStatus.Successful;
                    }
                    else
                    {
                        responsedata.Status = ResponseStatus.Failed;
                        responsedata.Error  = "Failed to create or update farm";
                    }
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                responsedata.Error  = "Failed to create or update farm";
                responsedata.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("FarmDetailsController :: CreateUpdateFarm failed :: " + ex.Message);
            }

            return(requestData);
        }
        public FarmDetailResponse GetFarmsDetails()
        {
            bool ret = default(bool);
            IEnumerable <FarmDetail> farmData     = null;
            FarmDetailResponse       responsedata = new FarmDetailResponse();

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];
                    AggieGlobalLogManager.Info("FarmDetailsController :: GetFarmsDetails started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new FarmManager(connectionString);
                    farmData = repo.GetFarmDetails(sessionObject._userId);
                    if (farmData != null && farmData.Count() > default(int))
                    {
                        responsedata.FarmId              = EncryptionHelper.AesEncryption(Convert.ToString(farmData.FirstOrDefault().FarmId), EncryptionKey.LOG);
                        responsedata.FarmName            = farmData.FirstOrDefault().FarmName;
                        responsedata.CoOpName            = farmData.FirstOrDefault().CoOpName;
                        responsedata.FarmAddress         = farmData.FirstOrDefault().FarmAddress;
                        responsedata.FarmEstablishedDate = farmData.FirstOrDefault().FarmEstablishedDate;
                        responsedata.FarmSize            = farmData.FirstOrDefault().FarmSize;
                        responsedata.FarmSizeUnit        = farmData.FirstOrDefault().FarmSizeUnit;
                        responsedata.Status              = ResponseStatus.Successful;
                    }
                    else
                    {
                        responsedata.Error  = "Failed to retreive data";
                        responsedata.Status = ResponseStatus.Failed;
                    }
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                responsedata.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("FarmDetailsController :: GetFarmsDetails failed :: " + ex.Message);
            }
            return(responsedata);
        }