private PoliceContext FetchContext()
        {
            HttpContext httpContext = HttpContext.Current;

            if (httpContext == null)
            {
#if DEBUG
                if (StaticContext == null)
                {
                    StaticContext = new PoliceContext();
                }
                return(StaticContext);
#else
                return(new PoliceContext());
#endif
            }

            const string key = "Police_PoliceContext";
            if (httpContext.Items[key] == null)
            {
                httpContext.Items.Add(key, new PoliceContext());
            }

            return(httpContext.Items[key] as PoliceContext);
        }
Ejemplo n.º 2
0
        public ActionResult ManagePassword(string s)
        {
            string oldPass     = Request.Form["oldPass"];
            string newPass     = Request.Form["newPass"];
            string confirmPass = Request.Form["confirmPass"];

            if (!System.Text.RegularExpressions.Regex.IsMatch(newPass, "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$"))
            {
                Session["Error"] = "رمز عبور میبایست به طول ۸ و شامل حروف کوچک، بزرگ و اعداد باشد.";
                return(RedirectToAction("ManagePassword", "Account"));
            }
            if (!newPass.Equals(confirmPass))
            {
                Session["Error"] = "رمزعبور جدید با تکرار آن مطابقت ندارد";
                return(RedirectToAction("ManagePassword", "Account"));
            }
            User user = Utilities.CommonUtilities.GetUser();

            if (!user.Password.Equals(oldPass))
            {
                Session["Error"] = "رمز عبور فعلی اشتباه است.";
                return(RedirectToAction("ManagePassword", "Account"));
            }
            PoliceContext ctn        = ContextCreator.GetInstance().GetContext();
            User          userUpdate = ctn.Users.FirstOrDefault(u => u.Username.Equals(user.Username));

            if (userUpdate != null)
            {
                userUpdate.Password = newPass;
            }
            ctn.SaveChanges();
            Session["Information"] = "رمز با موفقیت تغییر کرد.";
            return(RedirectToAction("MessagePage", "Default"));
        }
        public PoliceContext GetContext()
        {
            PoliceContext context = FetchContext();

            context.Database.CommandTimeout = 600;
            context.Configuration.UseDatabaseNullSemantics = true;
            return(context);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ایجاد کاربر جدید در سیستم
        /// </summary>
        /// <param name="fName"></param>
        /// <param name="lName"></param>
        /// <param name="nationalCode"></param>
        /// <param name="password"></param>
        /// <param name="roles"></param>
        public static void RegisterUser(string fName, string lName, string username, string organizationCode, string password, List <RoleType> roles)
        {
            PoliceContext context = Utilities.ContextCreator.GetInstance().GetContext();

            try
            {
                if (!Configuration.GetInstance().IsLocalMachin() && !CommonUtilities.CheckNationalNumber(username))
                {
                    throw new UserInterfaceException("کد ملی صحیح نمی باشد!");
                }
                if (roles.Count == 0)
                {
                    throw new UserInterfaceException("نقشی برای کاربر انتخاب نشده است!");
                }
                if (Repository.UserRepository.GetInstance().FindByNationalCode(username) != null)
                {
                    throw new UserInterfaceException(
                              "پیش از این کاربری با این شماره ملی ثبت شده است.");
                }
            }
            catch (EntityNotFoundException)
            {
                if (!Configuration.GetInstance().IsLocalMachin())
                {
                    if (context.Users.Any(u => u.Username.Equals(username)))
                    {
                        throw new UserInterfaceException("قبلا کاربری با این کد ملی ثبت شده است، لطفا کد ملی را اصلاح کرده و دوباره امتحان کنید.");
                    }
                }
                User savingUser = new User()
                {
                    Name             = fName,
                    Family           = lName,
                    Username         = username,
                    Password         = password,
                    OrganizationCode = organizationCode,
                };
                foreach (var role in roles)
                {
                    savingUser.Responsibilities.Add(new Responsibility(role));
                }
                context.Users.Add(savingUser);
                context.SaveChanges();

                //                foreach (RoleType role in roles)
                //                {
                //                    LogEventHelper.InsertLogEvent(new LogEvent()
                //                    {
                //                        TableName = "User",
                //                        RecordID = savingUser.ID,
                //                        IsSuccuessful = true,
                //                        LogActionID = LogActionRepository.GetInstance().GetUserResponsibility_AddAction(),
                //                        Description = String.Format("دسترسی {0} در تاریخ {1} به {2} توسط {3} داده شده است.", Utilities.RoleManager.GetInstance().GetFarsiRole(role), CommonUtilities.DateConverterMiladiToHijri(DateTime.Now), savingUser.GetFullName(), Utilities.CommonUtilities.GetUser().GetFullName()),
                //                    }, EventPriority.High);
                //                }
                //                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <error code ="10001"></error>
 /// <param name="cnt"></param>
 internal AbstractRepository(PoliceContext cnt = null)
 {
     try
     {
         Context = cnt ?? Utilities.ContextCreator.GetInstance().GetContext();
     }
     catch (Exception ex)
     {
         if (!CommonUtilities.IsUserInterfaceException(ex))
         {
             Log.Error(String.Format("Error Stoped Configuration in {0}'s constructor", GetName()), ex);
             throw new UserInterfaceException(10001, ExceptionMessage.ConstructoreFaild);
         }
         throw;
     }
 }
Ejemplo n.º 6
0
        private RoleManager()
        {
            _context = Utilities.ContextCreator.GetInstance().GetContext();

            _CreateRoles();
            _headerPermissions = new Dictionary <FarsiPage, List <Role> >();
            _pagePermissions   = new Dictionary <string, List <Role> >();
            _roleFarsi         = new Dictionary <RoleType, string>();

            _FillHeaderPermissions();
            _FillPagePermissions();
            _FillRoleFarsi();

            _onlineUsers = new List <User>();
            Log.Debug("A Role Manager Has Been Created");
        }
 public static UserRepository GetInstance(PoliceContext cnt = null)
 {
     return(new UserRepository(cnt));
 }
 private UserRepository(PoliceContext cnt = null) : base(cnt)
 {
 }
 private PatteRepository(PoliceContext cnt = null) : base(cnt)
 {
 }
 public static ConfirmedPatteRepository GetInstance(PoliceContext cnt = null)
 {
     return(new ConfirmedPatteRepository(cnt));
 }
Ejemplo n.º 11
0
 public static PasgahRepository GetInstance(PoliceContext cnt = null)
 {
     return(new PasgahRepository(cnt));
 }
Ejemplo n.º 12
0
 public static TicketRepository GetInstance(PoliceContext cnt = null)
 {
     return(new TicketRepository(cnt));
 }
Ejemplo n.º 13
0
 private TicketRepository(PoliceContext cnt = null) : base(cnt)
 {
 }
 public EFRepository(PoliceContext context)
 {
     this.context = context;
     dbSet        = context.Set <T>();
 }