/// <summary>
        /// Returns token Expires timespan
        /// </summary>
        /// <param name="refreshTokenLifeTime"></param>
        /// <param name="refreshTokenLifeTimeType"></param>
        /// <returns></returns>
        private TimeSpan GetExpiresTimeSpan(int?refreshTokenLifeTime, int?refreshTokenLifeTimeType)
        {
            try
            {
                TimeSpan timeSpan = TimeSpan.MaxValue;

                var gc = CommonDBFunctions.GetGlobalCode(refreshTokenLifeTimeType);

                if (gc.CodeName == "Day" && gc.Code == "TOKENLIFETIMEDAY")
                {
                    timeSpan = TimeSpan.FromDays(Convert.ToDouble(refreshTokenLifeTime));
                }
                else if (gc.CodeName == "Hour" && gc.Code == "TOKENLIFETIMEHOUR")
                {
                    timeSpan = TimeSpan.FromHours(Convert.ToDouble(refreshTokenLifeTime));
                }
                else if (gc.CodeName == "Minute" && gc.Code == "TOKENLIFETIMEMINUTE")
                {
                    timeSpan = TimeSpan.FromMinutes(Convert.ToDouble(refreshTokenLifeTime));
                }

                return(timeSpan);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in SimpleAuthorizationServerProvider.GetExpiresTimeSpan method." + ex.Message);
                throw excep;
            }
        }
示例#2
0
        protected void WriteTrace(TraceRecord record)
        {
            if (record != null && record.Exception != null)
            {
                int    staffId  = 0;
                string usercode = string.Empty;

                var queryString = record.Request.RequestUri.Query;
                if (!String.IsNullOrWhiteSpace(queryString))
                {
                    int.TryParse(System.Web.HttpUtility.ParseQueryString(queryString.Substring(1))["staffId"], out staffId);
                    usercode = CommonDBFunctions.GetCurrentUser(staffId);
                }
                else
                {
                    usercode = "MobileApi";
                }

                var errorMessage = string.Format(
                    "{0} {1}: Category={2}, Level={3} {4} {5} {6} {7}",
                    record.Request.Method.ToString(),
                    record.Request.RequestUri.ToString(),
                    record.Category,
                    record.Level,
                    record.Kind,
                    record.Operator,
                    record.Operation,
                    record.Exception != null ? record.Exception.GetBaseException().Message : !string.IsNullOrEmpty(record.Message) ? record.Message : string.Empty);

                _ctx.ssp_SCLogError(errorMessage, record.Exception.StackTrace, "MobileErrorTrace", usercode, DateTime.Now, "");
            }
        }
示例#3
0
 public Status InsertUser(UserExtend user)
 {
     DbParameter[] parameter =
     {
         DataParameter.GetSqlParam(dbUserEnity.Email.ToString(),      SqlDbType.VarChar,  30, user.Email,                 ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.UserName.ToString(),   SqlDbType.VarChar,  30, user.UserName,              ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.Password.ToString(),   SqlDbType.VarChar,  30, user.Password,              ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.FirstName.ToString(),  SqlDbType.VarChar,  30, user.FirstName,             ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.LastName.ToString(),   SqlDbType.VarChar,  30, user.LastName,              ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.Gender.ToString(),     SqlDbType.Int,      20, user.Gender,                ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.DOB.ToString(),        SqlDbType.DateTime, 30, user.DOB,                   ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.Status.ToString(),     SqlDbType.Int,      10, user.Status,                ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.SaltKey.ToString(),    SqlDbType.VarChar,   6, CommonFunctions.SaltKey(),  ParameterDirection.Input),
         DataParameter.GetSqlParam(dbUserEnity.ActiveGuid.ToString(), SqlDbType.VarChar,  50, Guid.NewGuid().ToString(),  ParameterDirection.Input),
         DataParameter.GetSqlParam("RETURN_VALUE",                    SqlDbType.Int,       0, ParameterDirection.Output),
     };
     try
     {
         return(new Status()
         {
             StatusId = CommonDBFunctions.ExecuteNonQuery(spUser.spUserInsert.ToString(), parameter), MsgDesc = AppConstant.SuccessMsg
         });
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Returns Token Expires Utc
        /// </summary>
        /// <param name="refreshTokenLifeTime"></param>
        /// <param name="refreshTokenLifeTimeType"></param>
        /// <param name="currentTime"></param>
        /// <returns></returns>
        private DateTime GetExpiresUtc(int?refreshTokenLifeTime, int?refreshTokenLifeTimeType, DateTime currentTime)
        {
            try
            {
                DateTime dateTime = DateTime.Now;

                var gc = CommonDBFunctions.GetGlobalCode(refreshTokenLifeTimeType);

                if (gc.CodeName == "Day" && gc.Code == "TOKENLIFETIMEDAY")
                {
                    dateTime = currentTime.AddDays(Convert.ToDouble(refreshTokenLifeTime));
                }
                else if (gc.CodeName == "Hour" && gc.Code == "TOKENLIFETIMEHOUR")
                {
                    dateTime = currentTime.AddHours(Convert.ToDouble(refreshTokenLifeTime));
                }
                else if (gc.CodeName == "Minute" && gc.Code == "TOKENLIFETIMEMINUTE")
                {
                    dateTime = currentTime.AddMinutes(Convert.ToDouble(refreshTokenLifeTime));
                }

                return(dateTime);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in SimpleAuthorizationServerProvider.GetExpiresUtc method." + ex.Message);
                throw excep;
            }
        }
示例#5
0
        /// <summary>
        /// Used to Authenticate With AD
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private bool AuthenticateWithActiveDirectory(string userName, string password)
        {
            try
            {
                bool authenticated = false;

                string domain = _scEntity.Staffs.Where(s => s.UserCode == userName).DefaultIfEmpty(null).Select(s => s.ActiveDirectoryStaff.ActiveDirectoryDomains.DomainName ?? "").FirstOrDefault().ToString();

                if (SC.Data.CommonDBFunctions.GetSystemConfigurationKeyValue("ValidateFromWebService").ToUpper() == "Y")
                {
                    SC.Data.SHSADAuthentication.ADAuthenticationService ad = new Data.SHSADAuthentication.ADAuthenticationService();
                    ad.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    ad.Url         = CommonDBFunctions.GetSystemConfigurationKeyValue("AuthWebServiceURL");

                    SC.Data.SHSADAuthentication.Authentication a = new Data.SHSADAuthentication.Authentication();
                    a.TokenKey             = CommonDBFunctions.GetSystemConfigurationKeyValue("WebServiceKeyToken");
                    ad.AuthenticationValue = a;

                    authenticated = ad.ValidateUser(userName.Trim(), password.Trim(), domain.Trim());
                }
                else
                {
                    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain))
                    {
                        authenticated = pc.ValidateCredentials(userName.Trim(), password.Trim());
                    }
                }
                return(authenticated);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in AuthRepository.AuthenticateWithActiveDirectory method." + ex.Message);
                throw excep;
            }
        }
        /// <summary>
        /// Save MyPreference Screen Data.
        /// </summary>
        /// <param name="stf"></param>
        /// <param name="loggedInUser"></param>
        /// <returns></returns>
        public async Task <_SCResult <Models.StaffPreferenceModel> > Save(StaffPreferences stf, int loggedInUser)
        {
            try
            {
                var _Ce = new _SCResult <Models.StaffPreferenceModel>();

                IBriefcaseRepository _repo       = new BriefcaseRepositiry(new SCMobile());
                List <Difference>    differences = new List <Difference>();
                bool modified = IsDataModified(stf.StaffPreferenceId, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE"), stf, out differences);

                if (modified)
                {
                    var original = _scEntity.StaffPreferences
                                   .Where(s => s.StaffPreferenceId == stf.StaffPreferenceId).FirstOrDefault();


                    foreach (var difference in differences)
                    {
                        string[] changedPprts = difference.PropertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

                        //Handled only objects which doesn't have sibling object
                        if (string.IsNullOrEmpty(difference.ParentPropertyName))
                        {
                            foreach (PropertyInfo propertyInfo in original.GetType().GetProperties())
                            {
                                if (changedPprts.Contains(propertyInfo.Name))
                                {
                                    propertyInfo.SetValue(original, propertyInfo.GetValue(stf, null), null);
                                }
                            }
                        }
                    }

                    _scEntity.SaveChanges();
                }
                _Ce.SavedResult = await _repo.GetMyPreference(stf.StaffId);

                _Ce.LocalstoreName       = "mypreference";
                _Ce.UnsavedId            = _Ce.SavedId = _Ce.SavedResult.StaffPreferenceId;
                _Ce.DeleteUnsavedChanges = true;
                _Ce.ShowDetails          = false;
                _Ce.Details     = null;
                _Ce.SavedResult = await FindMobileUser(stf.StaffId);

                if (stf != null)
                {
                    CommonFunctions <Models.StaffPreferenceModel> .CreateUpdateBriefcase(stf.StaffPreferenceId, _Ce.SavedResult, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE"));
                }

                return(_Ce);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in MobileStaffRepositiry.Save method." + ex.Message);
                throw excep;
            }
        }
示例#7
0
        public GroupList GetGroup(int userId)
        {
            DbParameter[] parameter =
            {
                DataParameter.GetSqlParam(dbUserEnity.CustomerID.ToString(), SqlDbType.Int, 50, userId, ParameterDirection.Input),
            };
            try
            {
                GroupList objGroupList  = new GroupList();
                var       drUserDetails = CommonDBFunctions.ExecuteDataSet(spUser.spUserLogin.ToString(), parameter);
                if (drUserDetails.Tables.Count > 0)
                {
                    //  new Status() { StatusId = AppConstant.Success, MsgDesc = success };
                    if (drUserDetails.Tables.Count == 1)
                    {
                        if (drUserDetails.Tables[1].Rows.Count > 0)
                        {
                            objGroupList.status = new Status()
                            {
                                StatusId = AppConstant.Success, MsgDesc = AppConstant.SuccessMsg
                            };
                        }
                        else
                        {
                            objGroupList.status = new Status()
                            {
                                StatusId = AppConstant.Information, MsgDesc = "No record"
                            };
                        }
                        foreach (DataRow dr in drUserDetails.Tables[1].Rows)
                        {
                            GroupDetails objGroup = new GroupDetails();
                            objGroup.GroupName   = dr[dbUserEnity.FirstName.ToString()].ToString();
                            objGroup.StatusMsg   = dr[dbUserEnity.FirstName.ToString()].ToString();
                            objGroup.Desc        = dr[dbUserEnity.FirstName.ToString()].ToString();
                            objGroup.CreatedUser = dr[dbUserEnity.FirstName.ToString()].ToString();
                            // objGroup.Status = dr[dbUserEnity.FirstName.ToString()].ToString();
                            objGroup.CreatedDate = Convert.ToDateTime(dr[dbUserEnity.LastLogin.ToString()].ToString());
                            objGroup.GroupID     = UtilCipher.Encrypt(dr[dbUserEnity.CustomerID.ToString()].ToString());
                            objGroup.IsAdmin     = Convert.ToBoolean(dr[dbUserEnity.FirstName.ToString()]);
                            objGroupList.groups.Add(objGroup);
                        }
                    }
                }


                return(objGroupList);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
示例#8
0
 public Status CheckGroup(string group)
 {
     DbParameter[] parameter =
     {
         DataParameter.GetSqlParam(DbGroupDetails.GroupName.ToString(), SqlDbType.VarChar, 50, group,                      ParameterDirection.Input),
         DataParameter.GetSqlParam("RETURN_VALUE",                      SqlDbType.Int,      0, ParameterDirection.Output),
     };
     try
     {
         return(new Status()
         {
             StatusId = CommonDBFunctions.ExecuteNonQuery("spGroupCheck", parameter, true), MsgDesc = AppConstant.SuccessMsg
         });
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
示例#9
0
        public Status Login1(UserEnity user)
        {
            DbParameter[] parameter =
            {
                DataParameter.GetSqlParam(dbUserEnity.UserName.ToString(), SqlDbType.VarChar, 50, user.UserName,              ParameterDirection.Input),
                DataParameter.GetSqlParam(dbUserEnity.Password.ToString(), SqlDbType.VarChar, 50, user.Password,              ParameterDirection.Input),
                DataParameter.GetSqlParam("RETURN_VALUE",                  SqlDbType.Int,      0, ParameterDirection.Output),
            };
            try
            {
                int    RES     = CommonDBFunctions.ExecuteNonQuery(spUser.spUserLogin.ToString(), parameter, true);
                string success = string.Empty;
                switch (RES)
                {
                case 1:
                    success = AppConstant.SuccessMsg;
                    break;

                case 2:
                    success = "User Removed";
                    break;

                case 8:
                    success = "User Locked";
                    break;

                case 9:
                    success = "Not activation";
                    break;
                }

                return(new Status()
                {
                    StatusId = AppConstant.Success, MsgDesc = success
                });
            }
            catch (SqlException ex)
            {
                throw ex;
            }
        }
示例#10
0
 public Status Insert(GroupDetails objGroup)
 {
     DbParameter[] parameter =
     {
         DataParameter.GetSqlParam(DbGroupDetails.GroupName.ToString(), SqlDbType.VarChar,  50, objGroup.GroupName,         ParameterDirection.Input),
         DataParameter.GetSqlParam(DbGroupDetails.Desc.ToString(),      SqlDbType.VarChar, 500, objGroup.Desc,              ParameterDirection.Input),
         DataParameter.GetSqlParam(DbGroupDetails.CreatedBy.ToString(), SqlDbType.Int,      11, objGroup.CreatedUser,       ParameterDirection.Input),
         DataParameter.GetSqlParam("RETURN_VALUE",                      SqlDbType.Int,       0, ParameterDirection.Output),
     };
     try
     {
         return(new Status()
         {
             StatusId = CommonDBFunctions.ExecuteNonQuery("spGroupInsert", parameter, true), MsgDesc = AppConstant.SuccessMsg
         });
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
示例#11
0
 public Status CheckUserActivation(string guid)
 {
     DbParameter[] parameter =
     {
         DataParameter.GetSqlParam(dbUserEnity.ActiveGuid.ToString(), SqlDbType.VarChar, 50, guid,                       ParameterDirection.Input),
         DataParameter.GetSqlParam("RETURN_VALUE",                    SqlDbType.Int,      0, ParameterDirection.Output),
     };
     try
     {
         int    RES     = CommonDBFunctions.ExecuteNonQuery(spUser.spCheckActivation.ToString(), parameter, true);
         string success = (RES == 1) ? AppConstant.SuccessMsg : (RES == 2) ? "Activation done already" : "No activation code";
         return(new Status()
         {
             StatusId = AppConstant.Success, MsgDesc = success
         });
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
示例#12
0
        /// <summary>
        /// Get All the Appointments for the staff based on MobileCalendarEventsDaysLookUpInPast and MobileCalendarEventsDaysLookUpInFuture
        /// </summary>
        /// <param name="StaffId"></param>
        /// <returns></returns>
        public List <Models.AppointmentModel> GetCalanderEvents(int StaffId)
        {
            try
            {
                List <Models.AppointmentModel> appointments = new List <Models.AppointmentModel>();

                var mobStaff = (from a in _ctx.StaffPreferences
                                where a.StaffId == StaffId
                                select new
                {
                    backfromCurrentDate = a.MobileCalendarEventsDaysLookUpInPast,
                    forwardfromCurrentDate = a.MobileCalendarEventsDaysLookUpInFuture
                }).FirstOrDefault();
                DateTime dtStart = DateTime.Now.AddDays(-(double)mobStaff.backfromCurrentDate);
                DateTime dtEnd   = DateTime.Now.AddDays((double)mobStaff.forwardfromCurrentDate);
                dtEnd = dtEnd.Date.Add(new TimeSpan(23, 59, 59));// To Consider the complete Day

                List <Models.AppointmentModel> events = GetServiceAppointments(StaffId, dtStart, dtEnd);
                appointments.AddRange(events);

                foreach (var calevent in events)
                {
                    if (calevent != null)
                    {
                        var briefcaseType = calevent.Service == null?CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "APPOINTMENT") : CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "SERVICE");

                        CommonFunctions <Models.AppointmentModel> .CreateUpdateBriefcase(calevent.AppointmentId, calevent, StaffId, briefcaseType);
                    }
                }

                return(appointments);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in BriefcaseRepositiry.GetCalanderEvents method." + ex.Message);
                throw excep;
            }
        }
示例#13
0
        /// <summary>
        /// Retusn My Preference Data for the loggedin staff
        /// </summary>
        /// <param name="currentStaffId"></param>
        /// <returns></returns>
        public async Task <Models.StaffPreferenceModel> GetMyPreference(int currentStaffId)
        {
            try
            {
                var repo = new MobileStaffRepositiry(new SC.Data.SCMobile());
                var user = await repo.FindMobileUser(currentStaffId);

                if (user != null)
                {
                    CommonFunctions <Models.StaffPreferenceModel> .CreateUpdateBriefcase(user.StaffPreferenceId, user, currentStaffId, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE"));
                }

                return(user);
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in BriefcaseRepositiry.GetMyPreference method." + ex.Message);
                throw excep;
            }
        }