public LoginResponseMessage AuthenticateUser(LoginRequestMessage RequestMessage)
        {
            LoginResponseMessage response = null;

            try
            {
                response = ValidateAuthenticateUser(RequestMessage);

                if (response != null && response.Error == null)
                {
                    loginDataProvider = new LoginDataProvider();
                    response          = loginDataProvider.AuthenticateUser(RequestMessage);

                    if (response != null && response.Error == null)
                    {
                        //Generate token
                        response.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.WriteLog(response, "999", ex.Message, ex: ex);
            }
            return(response);
        }
示例#2
0
        public LoginResponseMessage AuthenticateUser(LoginRequestMessage RequestMessage)
        {
            LoginResponseMessage response = new LoginResponseMessage();

            try
            {
                StringBuilder sqlString = new StringBuilder();

                sqlString.Append("select Loginid from LoginDtls where LoginName='");
                sqlString.Append(RequestMessage.LoginName);
                sqlString.Append("' and cast(Password as varbinary(20))=cast('");
                sqlString.Append(RequestMessage.Password);
                sqlString.Append("' as varbinary(50)) and IsActive=1");

                var login = DataAccessLayer.ExecuteScalar(sqlString.ToString());

                if (login != null)
                {
                    response.SecurityToken = "G";
                }
                else
                {
                    ErrorLogManager.WriteLog(response, "000", "Unable to find user.");
                }
            }
            catch (Exception ex)
            {
                //ErrorLogManager.WriteLog(response, "999", ex.Message,ex:ex);
                ErrorLogManager.WriteLog(response, "012", ex.Message, ex: ex);
            }
            return(response);
        }
        private UploadResponseMessage ValidateFile(UploadRequestMessage requestMessage)
        {
            UploadResponseMessage response = new UploadResponseMessage();

            if (requestMessage == null)
            {
                ErrorLogManager.WriteLog(response, "TestFile", "002", "Request message should not be empty.");
            }
            else
            {
                if (string.IsNullOrEmpty(requestMessage.LoginName))
                {
                    ErrorLogManager.WriteLog(response, "TestFile", "003", "Login name is mandatory.");
                }

                if (string.IsNullOrEmpty(requestMessage.Password))
                {
                    ErrorLogManager.WriteLog(response, "TestFile", "004", "Password is mandatory.");
                }


                if (requestMessage.gpxFiles == null)
                {
                    ErrorLogManager.WriteLog(response, "TestFile", "005", "File list should not be empty.");
                }
                else
                {
                    //var item = requestMessage.FileList;
                    foreach (var item in requestMessage.gpxFiles)
                    {
                        if (string.IsNullOrEmpty(item.FileName))
                        {
                            ErrorLogManager.WriteLog(response, item.FileName, "006", "File name is mandatory.");
                        }

                        if (item.FileData == null)
                        {
                            ErrorLogManager.WriteLog(response, item.FileName, "007", "File data should not be empty.");
                        }

                        if (item.FileData != null && item.FileData.Length == 0)
                        {
                            ErrorLogManager.WriteLog(response, item.FileName, "007", "File data should not be empty.");
                        }
                    }
                }
            }
            return(response);
        }
        public UploadResponseMessage UploadFile(UploadRequestMessage requestMessage, string filePath = "")
        {
            UploadResponseMessage response = new UploadResponseMessage();

            try
            {
                response = ValidateFile(requestMessage);

                if (response != null && response.Log == null)
                {
                    uploadFileDataProvider = new UploadDataProvider();
                    response = uploadFileDataProvider.UploadFile(requestMessage, filePath);
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.WriteLog(response, "TestFile", "999", ex.Message, true, ex: ex);
            }
            return(response);
        }
        private LoginResponseMessage ValidateAuthenticateUser(LoginRequestMessage RequestMessage)
        {
            LoginResponseMessage response = new LoginResponseMessage();

            if (RequestMessage == null)
            {
                ErrorLogManager.WriteLog(response, "002", "Request message should not be empty.");
            }
            else
            {
                if (string.IsNullOrEmpty(RequestMessage.LoginName))
                {
                    ErrorLogManager.WriteLog(response, "003", "Login name is mandatory.");
                }

                if (string.IsNullOrEmpty(RequestMessage.Password))
                {
                    ErrorLogManager.WriteLog(response, "004", "Password is mandatory.");
                }
            }
            return(response);
        }
示例#6
0
        protected void Upload(UploadFile PostedFile,
                              UploadResponseMessage response, string filePath)
        {
            string FileName = string.Empty;

            try
            {
                BCCityAdmin cityContent   = new BCCityAdmin();
                DateTime    cityStartDate = new DateTime();
                DataTable   _dtTrkpts     = new DataTable();
                DataTable   studInfo      = null;
                FileName = PostedFile.FileName;
                string NewFile     = "";
                string NewFileName = "";
                string FilePath    = string.Empty;


                studInfo = objStudent.GetMyProfileInfo(studentId);
                schoolId = Convert.ToInt32(studInfo.Rows[0]["SchoolId"]);
                classId  = Convert.ToInt32(studInfo.Rows[0]["ClassId"]);

                FilePath = filePath + schoolId + @"\" +
                           classId + @"\" + studentId.ToString() + @"\".ToString();


                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(FilePath);
                if (!(dir.Exists))
                {
                    System.IO.Directory.CreateDirectory(FilePath);
                }
                //string extension = System.IO.Path.GetExtension(FileName).ToLower();
                string[] extention = FileName.Split('.');
                if (extention != null && extention.Count() > 0)
                {
                    FileName = extention[0];
                }

                //if ((extension == ".gpx") | (extension == ".GPX"))
                //{
                if (IsFileUploaded(FilePath + FileName + ".xml"))
                {
                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                }
                else
                {
                    #region Save file on server for evaluation

                    File.WriteAllBytes(FilePath + FileName + ".xml", PostedFile.FileData);
                    DataTable dt = cityContent.GetCityContent(Convert.ToInt32(studInfo.Rows[0]["CityId"]), 0);

                    try
                    {
                        string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                                           DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "";

                        NewFileName = UserRoleId.ToString() + "_" + UserId.ToString() + "_" + TimeStamp + ".xml";
                        File.Move(FilePath + FileName + ".xml", FilePath + NewFileName); // Try to move
                        NewFile = FilePath + NewFileName;
                    }
                    catch (IOException ex)
                    {
                        NewFile     = FilePath + FileName;
                        NewFileName = FileName;
                    }

                    //File.WriteAllBytes(FilePath + FileName + ".xml", PostedFile.FileData);
                    ////fu_UploadGpx.SaveAs(FilePath + FileName.Replace(".gpx", ".xml"));
                    //DataTable dt = cityContent.GetCityContent(cityId, 0);
                    //XElement root = null;
                    //DateTime DateOfFile = new DateTime();
                    //try
                    //{
                    //    root = XElement.Load(FilePath + FileName + ".xml");
                    //    DateOfFile = DateTime.Parse(root.Elements().Skip(1).Take(1).Elements().Take(1).ToList()[0].Value);
                    //}
                    //catch (Exception ex)
                    //{
                    //    ErrorLogManager.WriteLog(response,FileName, "009", "Uploaded File does not have Time Information, Please check the file and re-upload");
                    //    return;
                    //}
                    //if (dt != null && dt.Rows.Count > 0)
                    //{
                    //    cityStartDate = (dt.Rows[0]["CityStartDate"] != DBNull.Value ? Convert.ToDateTime(dt.Rows[0]["CityStartDate"]) : new DateTime());

                    //    if (cityStartDate != new DateTime() &&
                    //        DateOfFile != new DateTime() &&
                    //        DateOfFile.Date <= cityStartDate.Date)
                    //    {
                    //        ErrorLogManager.WriteLog(response,FileName, "010", "File can not be uploaded prior to Batch Start Date.");
                    //        return;
                    //    }
                    //}
                    //try
                    //{
                    //    string TimeStamp = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() +
                    //    DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "";

                    //    NewFileName = UserRoleId.ToString() + "_" + UserId.ToString() + "_" + TimeStamp + ".xml";
                    //    File.Move(FilePath + FileName + ".xml", FilePath + NewFileName); // Try to move
                    //    NewFile = FilePath + NewFileName;
                    //}
                    //catch (IOException ex)
                    //{
                    //    NewFile = FilePath + FileName + ".xml";
                    //    NewFileName = FileName;
                    //}

                    #endregion

                    DataTable dtNew = new DataTable();
                    dtNew = LoadGPXWaypoints(NewFile);
                    DateTime DateOfFile = DateTime.MinValue;;
                    if (dt != null && dt.Rows.Count > 0 && dtNew != null && dtNew.Rows.Count > 0)
                    {
                        cityStartDate = Convert.ToDateTime(dt.Rows[0]["CityStartDate"]);
                        DateOfFile    = Convert.ToDateTime(dtNew.Rows[0]["time"]);
                    }

                    if ((cityStartDate != new DateTime() &&
                         DateOfFile <= cityStartDate) ||
                        (DateOfFile < DateTime.Parse(ConfigurationManager.AppSettings["BatchStartDate"])))
                    {
                        ErrorLogManager.WriteLog(response, FileName, "010", "File can not be uploaded prior to Batch Start Date.");
                        return;
                    }

                    _dtTrkpts = dtNew;
                    int    trackCount   = dtNew.Rows.Count; //(dtNew.Rows.Count / 5) + 1;
                    double highestSpeed = 0;

                    DataTable dtNewRows = CheckPreviousGPXTrackPointsNew(UserId,
                                                                         schoolId,
                                                                         classId, dtNew);

                    if (dtNewRows != null &&
                        dtNewRows.Rows.Count > 0)
                    {
                        double distance = CalculateTotalDistance(dtNewRows);
                        double time     = CalculateTotalTime(dtNewRows);
                        double timeAvg  = CalculateAvgTime(dtNewRows);

                        #region Calculate Average Speed

                        if (timeAvg > 0)
                        {
                            time = timeAvg;
                        }

                        double avgSpeed = 0.0;
                        if (time > 0)
                        {
                            avgSpeed = distance / time;
                        }

                        #endregion

                        int speedLimit = 15;

                        if (ConfigurationManager.AppSettings["SpeedLimit"].ToString() != "")
                        {
                            speedLimit = Convert.ToInt32(ConfigurationManager.AppSettings["SpeedLimit"]);
                        }

                        if (avgSpeed == 0)
                        {
                            ErrorLogManager.WriteLog(response, FileName, "011", "Invalid file!");
                            File.Delete(NewFile);
                        }
                        else
                        {
                            highestSpeed = GetHighestSpeedInGPX(dtNewRows);

                            #region Check ongoing stage information

                            int     stagePlanId   = 0;
                            double  stageDistance = 0;
                            double  distCovered   = 0;
                            DataSet _dtStage      = objStudent.GetCurrentStageInfo((studentId > 0 ? studentId : UserId),
                                                                                   UserRoleId, classId);
                            if (_dtStage.Tables[0].Rows.Count > 0)
                            {
                                stagePlanId   = Convert.ToInt32(_dtStage.Tables[0].Rows[0]["StagePlanId"]);
                                stageDistance = Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance"]);
                                distCovered   = double.Parse(_dtStage.Tables[0].Rows[0]["Distance_Covered"].ToString(), System.Globalization.CultureInfo.InvariantCulture);
                                //Convert.ToDouble(_dtStage.Tables[0].Rows[0]["Distance_Covered"]);
                            }

                            #endregion
                            //if (avgSpeed > speedLimit)
                            //{
                            //    ErrorLogManager.WriteLog(response, FileName, "016", "Speed Limit Crossed!");
                            //}
                            //else
                            if (avgSpeed <= speedLimit && highestSpeed <= speedLimit)
                            {
                                //Save data in Student Uploads

                                #region Save data in Student Uploads

                                // Check for similar track points


                                int res = objStudent.StudentsUpload(
                                    UserRoleId, UserId,
                                    0, studentId,
                                    stagePlanId, stageDistance, distCovered, (NewFile), NewFileName,
                                    DateTime.Now, distance, time, classId, 1, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);
                                    ErrorLogManager.WriteLog(response, FileName, "012", "File uploaded successfully!", false);
                                }
                                else
                                {
                                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                                    File.Delete(NewFile);
                                }

                                #endregion
                            }
                            else // Upload file out of speed limit. No change in stage distance.
                            {
                                #region Save data in Student Uploads
                                int res = objStudent.StudentsUploadExtraSpeed(
                                    UserRoleId, UserId,
                                    0,
                                    studentId, stagePlanId,
                                    stageDistance, distCovered, (NewFile), NewFileName,
                                    DateTime.Now, distance, time, classId, 0, trackCount);
                                if (res > 0)
                                {
                                    _SaveTrackPoints(_dtTrkpts, res);
                                    #region Send email to Class Admin & City Admin for speed limit

                                    if (avgSpeed > speedLimit || highestSpeed > speedLimit)
                                    {
                                        try
                                        {
                                            string ClassAdminEmail = studInfo.Rows[0]["ClassAdminEmail"].ToString();
                                            string CityAdminEmail  = studInfo.Rows[0]["CityAdminEmail"].ToString();

                                            StringBuilder sb = new StringBuilder();
                                            sb.Append("<p>Dear " + studInfo.Rows[0]["ClassAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + UserName + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + " Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb.ToString());

                                            StringBuilder sb2 = new StringBuilder();
                                            sb2.Append("<p>Dear " + studInfo.Rows[0]["CityAdminName"].ToString() + ",</p>");
                                            sb.Append("<p><b>" + UserName + " (Student in " + studInfo.Rows[0]["School"].ToString() + ", " + studInfo.Rows[0]["Class"].ToString() + ")</b> have uploaded a GPX file (" + NewFileName + ") with speed <b>" + avgSpeed.ToString() + "Kmph and heighest speed being " + highestSpeed + "</b>.</p>");
                                            sb.Append("<p>Kindly approve or reject file manually.</p>");
                                            Helper.sendMailMoreThanAvgSpeed("BikeTour - Speed Limit Crossed!", ClassAdminEmail, sb2.ToString());
                                        }
                                        catch (Exception ex)
                                        {
                                        }
                                    }

                                    #endregion
                                    ErrorLogManager.WriteLog(response, FileName, "012", "File uploaded successfully!", false);
                                }
                                else
                                {
                                    ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                                    File.Delete(NewFile);
                                }

                                #endregion
                            }
                        }
                    }
                    else
                    {
                        ErrorLogManager.WriteLog(response, FileName, "008", "File already uploaded!");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.WriteLog(response, FileName, "013", "Select GPX file!" + ex.Message);
            }
        }
示例#7
0
        public UploadResponseMessage UploadFile(UploadRequestMessage requestMessage, string filePath = "")
        {
            UploadResponseMessage response = new UploadResponseMessage();

            response.Log = new List <UploadFileStatus>();

            try
            {
                StringBuilder sqlString = new StringBuilder();

                sqlString.Append("select * from LoginDtls where LoginName='");
                sqlString.Append(requestMessage.LoginName);
                sqlString.Append("' and cast(Password as varbinary(20))=cast('");
                sqlString.Append(requestMessage.Password);
                sqlString.Append("' as varbinary(50)) and IsActive=1");

                var login = DataAccessLayer.ReturnDataTable(sqlString.ToString());

                if (login != null && login.Rows != null && login.Rows.Count > 0)
                {
                    UserRoleId = Convert.ToInt32(login.Rows[0]["RoleId"]);
                    UserId     = Convert.ToInt32(login.Rows[0]["LoginId"]);
                    UserName   = Convert.ToString(login.Rows[0]["LoginName"]);

                    if (UserRoleId == 5)
                    {
                        sqlString = new StringBuilder();
                        sqlString.Append("Select * FROM StudentMaster Where LoginId = ");
                        sqlString.Append(UserId);

                        var student = DataAccessLayer.ReturnDataTable(sqlString.ToString());
                        if (student != null && student.Rows.Count > 0)
                        {
                            schoolId  = Convert.ToInt32(student.Rows[0]["SchoolId"]);
                            classId   = Convert.ToInt32(student.Rows[0]["ClassId"]);
                            cityId    = Convert.ToInt32(student.Rows[0]["CityId"]);
                            studentId = Convert.ToInt32(student.Rows[0]["StudentId"]);
                        }
                    }
                    else
                    {
                        ErrorLogManager.WriteLog(response, "TestFile", "013", "Only Student can upload file.");
                        return(response);
                    }
                    //throw new Exception("To Verify the Error log file writting");

                    //var item = requestMessage.FileData;
                    foreach (var item in requestMessage.gpxFiles)
                    {
                        Upload(item, response, filePath);
                    }
                }
                else
                {
                    ErrorLogManager.WriteLog(response, "TestFile", "000", "Unable to find user.");
                }
            }
            catch (Exception ex)
            {
                ErrorLogManager.WriteLog(response, "TestFile", "999", ex.Message, ex: ex);
            }

            return(response);
        }