public AccountResponse GetUserDetails()
        {
            AccountResponse userData    = null;
            var             httpContent = Request.Content;

            try
            {
                string userId = string.Empty;

                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 AccountManager(connectionString);
                    userData        = repo.GetAcountByUserClientData(sessionObject._email, sessionObject._userId, sessionObject._deviceid);
                    userData.Status = ResponseStatus.Successful;
                    return(userData);
                }
                else
                {
                    userData        = new AccountResponse();
                    userData.Error  = "Invalid credentials";
                    userData.Status = ResponseStatus.Failed;
                }
            }
            catch (Exception ex)
            {
                userData        = new AccountResponse();
                userData.Error  = "failed to retreive user data";
                userData.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("FarmDetailsController :: GetFarmsDetails failed :: " + ex.Message);
            }
            return(userData);
        }
Beispiel #2
0
        public IList <SoilDataResponse> GetSoilDetails()
        {
            IList <SoilDataResponse> dataresponse = new List <SoilDataResponse>();

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];

                    AggieGlobalLogManager.Info("PlotController :: GetSoilDetails started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new PlotManager(connectionString);
                    dataresponse = repo.GetSoilDetails();
                    repo.Dispose();
                }
            }
            catch (Exception e)
            {
                SoilDataResponse det = new SoilDataResponse();
                det.Status = ResponseStatus.Failed;
                det.Error  = "Failed to retreive data";
                dataresponse.Add(det);
                AggieGlobalLogManager.Fatal("AccountRepository :: LoginCheck failed :: " + e.Message);
            }
            return(dataresponse);
        }
        public AccountResponse UpdateSession()
        {
            int             ret   = default(int);
            AccountResponse ibase = new AccountResponse();

            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 AccountManager(connectionString);
                    ret = repo.UpdateSession(sessionObject._email, sessionObject._userId, sessionObject._deviceid);
                    if (ret == 0)
                    {
                        ibase.Status = ResponseStatus.Successful;
                        ibase.Error  = "Invalid credentials";
                    }
                }
            }
            catch (Exception ex)
            {
                ibase.Status = ResponseStatus.Failed;
                ibase.Error  = "Invalid credentials";
                AggieGlobalLogManager.Fatal("FarmDetailsController :: GetFarmsDetails failed :: " + ex.Message);
            }
            return(ibase);
        }
Beispiel #4
0
        public AccountResponse SignIn(string username, string password, string userDeviceId)
        {
            bool            res   = default(bool);
            AccountResponse ibase = new AccountResponse();

            try
            {
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
                {
                    ibase.Status = ResponseStatus.Failed;
                    ibase.Error  = "Required parameters not set";
                }
                else
                {
                    AggieGlobalLogManager.Info("RegistrationController :: SignIn started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new AccountManager(connectionString);
                    ibase.Status    = ResponseStatus.Successful;
                    ibase.AuthToken = repo.LoginCheck(username, password, userDeviceId);
                    if (string.IsNullOrEmpty(ibase.AuthToken))
                    {
                        ibase.Error = "Invalid credentials";
                    }
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                ibase.Status = ResponseStatus.Failed;
                ibase.Error  = "Login failed || " + ex.Message;
                AggieGlobalLogManager.Fatal("RegistrationController :: SignIn failed :: " + ex.Message);
            }
            return(ibase);
        }
        public bool CreateAccount(Account userData, out bool IsDuplicate)
        {
            try
            {
                DbTransaction transaction = null;
                int           result      = default(int);
                IsDuplicate = false;
                using (var connection = GetConnection())
                {
                    try
                    {
                        connection.Open();
                        transaction      = connection.BeginTransaction();
                        userData.optMode = 2;
                        AggieGlobalLogManager.Info("RegistrationController :: Registration started  Account Repository");
                        CreateRecordWithinTransaction("CreateAccount", transaction, userData.FirstName, userData.LastName, userData.password, userData.Address, userData.EmailId, userData.FarmId, userData.UserDeviceId, userData.optMode, userData.AuthenticationSuccessmode);
                        result = 1;
                        transaction.Commit();
                        AggieGlobalLogManager.Info("RegistrationController :: Registration ended  Account Repository");

                        if (result == 1)
                        {
                            int userNewId = GetAcountUserIdByEmail(userData.EmailId, userData.UserDeviceId);
                            userData.UserId    = userNewId;
                            userData.AuthToken = EncryptionHelper.AesEncryption(userData.EmailId + "-" + userNewId + "-" + userData.UserDeviceId, EncryptionKey.LOG);
                            return((result == 1) ? true : false);
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = string.Empty;
                        using (System.IO.StringReader reader = new System.IO.StringReader(ex.Message))
                        {
                            error = reader.ReadLine();
                        }
                        string[] errorObj = null;
                        if (!string.IsNullOrEmpty(error))
                        {
                            errorObj = error.Split(Environment.NewLine.ToCharArray());
                        }
                        if (errorObj[0] == "1"? IsDuplicate = true:false)
                        {
                            result = 0;
                        }
                        AggieGlobalLogManager.Fatal("RegistrationController :: Register failed :: " + ex.Message);
                        return(Convert.ToBoolean(userData.AuthenticationSuccessmode));
                    }
                    return(Convert.ToBoolean(result));
                }
            }
            catch (Exception e)
            {
                AggieGlobalLogManager.Fatal("AccountRepository :: CreateAccount failed :: " + e.Message);
            }
            IsDuplicate = false;
            return(Convert.ToBoolean(userData.AuthenticationSuccessmode));
        }
Beispiel #6
0
        public IEnumerable <PlotDetailResponse> GetPlotDetailsById(string plotid)
        {
            plotid = plotid.Replace("+", "%20");
            plotid = System.Net.WebUtility.UrlDecode(plotid);
            plotid = plotid.Replace(" ", "+");

            bool res = default(bool);
            IList <PlotDetailResponse> responsedata  = new List <PlotDetailResponse>();
            IEnumerable <PlotDetail>   internalPlots = null;

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];
                    AggieGlobalLogManager.Info("PlotController :: CreateUpdatePlot started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new PlotManager(connectionString);
                    internalPlots = repo.GetPlotDetailsById(plotid);
                    if (internalPlots != null && internalPlots.Count() > default(int))
                    {
                        foreach (PlotDetail det in internalPlots)
                        {
                            PlotDetailResponse resdata = new PlotDetailResponse();
                            resdata.PlotId   = EncryptionHelper.AesEncryption(Convert.ToString(det.PlotId), EncryptionKey.LOG);
                            resdata.FarmId   = EncryptionHelper.AesEncryption(Convert.ToString(det.FarmId), EncryptionKey.LOG);
                            resdata.PlotName = det.PlotName;
                            resdata.PlotSize = det.PlotSize;
                            resdata.Organic  = det.Organic;
                            resdata.SoilId   = Convert.ToString(EncryptionHelper.AesEncryption(det.SoilId.ToString(), EncryptionKey.LOG));
                            resdata.SoilPhId = Convert.ToString(EncryptionHelper.AesEncryption(det.SoilPhId.ToString(), EncryptionKey.LOG));
                            resdata.Notes    = det.Notes;
                            resdata.Status   = ResponseStatus.Successful;
                            responsedata.Add(resdata);
                        }
                    }
                    else
                    {
                        PlotDetailResponse resdata = new PlotDetailResponse();
                        resdata.Status = ResponseStatus.Failed;
                        resdata.Error  = "Unable to retireve plot detail";
                        responsedata.Add(resdata);
                    }
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                PlotDetailResponse resdata = new PlotDetailResponse();
                resdata.Status = ResponseStatus.Failed;
                resdata.Error  = "Unable to retireve plot details";
                responsedata.Add(resdata);
                AggieGlobalLogManager.Fatal("PlotController :: CreateUpdatePlot failed :: " + ex.Message);
            }

            return(responsedata);
        }
        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);
        }
Beispiel #8
0
        public PlotDetailResponse CreateUpdatePlot([FromBody] PlotDetailResponse det)
        {
            string str = Newtonsoft.Json.JsonConvert.SerializeObject(det);

            bool res = default(bool);

            if (det.PlotName == string.Empty && det.PlotSize <= default(int) && det.FarmId == string.Empty)
            {
                det.Error  = "Failed to create or update farm request structure invalid";
                det.Status = ResponseStatus.Failed;
                return(det);
            }

            try
            {
                if (HttpContext.Current.Session[ApplicationConstant.UserSession] != null)
                {
                    SessionData sessionObject = (SessionData)HttpContext.Current.Session[ApplicationConstant.UserSession];

                    PlotDetail resdata = new PlotDetail();
                    resdata.PlotName = det.PlotName;
                    resdata.PlotSize = det.PlotSize;
                    resdata.Organic  = det.Organic;
                    resdata.SoilId   = string.IsNullOrEmpty(det.SoilId) == true?default(int):Convert.ToInt32(EncryptionHelper.AesDecryption(det.SoilId, EncryptionKey.LOG));
                    resdata.SoilPhId = string.IsNullOrEmpty(det.SoilPhId) == true ? default(int) : Convert.ToInt32(EncryptionHelper.AesDecryption(det.SoilPhId, EncryptionKey.LOG));
                    resdata.Notes    = det.Notes;
                    resdata.FarmId   = Convert.ToInt32(EncryptionHelper.AesDecryption(det.FarmId, EncryptionKey.LOG));
                    resdata.PlotId   = !string.IsNullOrEmpty(det.PlotId) ? Convert.ToInt32(EncryptionHelper.AesDecryption(det.PlotId, EncryptionKey.LOG)) : 0;
                    resdata.UserID   = sessionObject._userId;

                    AggieGlobalLogManager.Info("PlotController :: CreateUpdatePlot started ");
                    var connectionString = "AggieGlobal";
                    var repo             = new PlotManager(connectionString);
                    res        = repo.CreateUpdatePlot(resdata);
                    det.Status = ResponseStatus.Successful;
                    det.PlotId = EncryptionHelper.AesEncryption(resdata.PlotId.ToString(), EncryptionKey.LOG);
                    repo.Dispose();
                }
            }
            catch (Exception ex)
            {
                det.Error  = "Failed to create or update farm";
                det.Status = ResponseStatus.Failed;
                AggieGlobalLogManager.Fatal("PlotController :: CreateUpdatePlot failed :: " + ex.Message);
            }

            return(det);
        }
        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);
        }
Beispiel #11
0
        protected void Application_Start()
        {
            //AreaRegistration.RegisterAllAreas();
            //GlobalConfiguration.Configure(WebApiConfig.Register);
            //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //RouteConfig.RegisterRoutes(RouteTable.Routes);


            //Http Client Protocol Settings
            System.Net.ServicePointManager.Expect100Continue       = false;
            System.Net.ServicePointManager.MaxServicePointIdleTime = 60 * 60 * 1000;//60 Minutes
            ServicePointManager.DefaultConnectionLimit             = 132;


            FileInfo fi = new FileInfo(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "\\web.config");

            log4net.Config.XmlConfigurator.ConfigureAndWatch(fi);

            Assembly     assem     = Assembly.GetExecutingAssembly();
            AssemblyName assemName = assem.GetName();

            AggieGlobalLogManager.Info("=================================================================");
            AggieGlobalLogManager.Info("Starting SKYSITE-Web-API-Service v{0}", assemName.Version);
            AggieGlobalLogManager.Info("=================================================================");

            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            FilterConfig.RegisterHttpFilters(GlobalConfiguration.Configuration.Filters);

            RouteConfig.RegisterRoutes(RouteTable.Routes);


            FormatterConfig.RegisterFormatters(GlobalConfiguration.Configuration.Formatters);
            HandlerConfig.RegisterHandlers(GlobalConfiguration.Configuration.MessageHandlers);

            //Instnatiate the one & only instance of GlobalApp - facade design pattern to Provide an unified interface to a set of interfaces to deal with business functions
            if (_theGlobalApp == null)
            {
                string dbConnectionStringName = "AggieGlobalDB";
                GlobalApp.Initialize(dbConnectionStringName);
                _theGlobalApp = GlobalApp.Instance;
            }
        }
        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);
        }
Beispiel #13
0
        public AccountResponse Register([FromBody] Account userData)
        {
            bool            res   = default(bool);
            AccountResponse ibase = new AccountResponse();

            try
            {
                if (userData == null)
                {
                    ibase.Status = ResponseStatus.Failed;
                    ibase.Error  = "Required parameters not set";
                }
                else
                {
                    AggieGlobalLogManager.Info("RegistrationController :: Registration started ");
                    var  connectionString = "AggieGlobal";
                    var  repo             = new AccountManager(connectionString);
                    bool IsDuplicate      = false;
                    //res = AccountManager.CreateAccount(userData, out IsDuplicate);
                    res             = repo.CreateAccount(userData, out IsDuplicate);
                    ibase.Status    = ResponseStatus.Successful;
                    ibase.AuthToken = userData.AuthToken;
                    ibase.FarmId    = (userData.FarmId) > default(int) ? string.Empty : Convert.ToString(EncryptionHelper.AesEncryption(userData.FarmId.ToString(), EncryptionKey.LOG));
                    if (res == default(bool))
                    {
                        ibase.Status = ResponseStatus.Failed;
                        ibase.Error  = (IsDuplicate == true ? "Sorry! A User exists with same Email" : "Registration failed");
                    }
                    repo.Dispose();
                    AggieGlobalLogManager.Info("RegistrationController :: Registration Completed ");
                }
            }
            catch (Exception ex)
            {
                ibase.Error = "Registration failed || " + ex.Message;
                AggieGlobalLogManager.Fatal("RegistrationController :: Register failed :: " + ex.Message);
            }

            return(ibase);
        }
Beispiel #14
0
 private GlobalApp(string dbConnectionStringName)
 {
     AggieGlobalLogManager.Info("Instantiating the 1 & only GlobalApp instance [#:{0}]", GetHashCode());
     this._dbConnectionStringName = dbConnectionStringName;
 }
Beispiel #15
0
 protected void Application_End()
 {
     AggieGlobalLogManager.Info("=================================================================");
     AggieGlobalLogManager.Info("Exiting SKYSITE-Web-API-Service.");
     AggieGlobalLogManager.Info("=================================================================");
 }