Exemplo n.º 1
0
        public ServiceResult <object> GridView(BusinessParam bp)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                var tableName   = Util.GetSqlServerTableName <DataLayer.Model.Core.File.File>();
                var queryString = $"select * from (SELECT * FROM {tableName}) e" +
                                  QueryUtil.GetWhereClause(bp.Clause,
                                                           QueryUtil.GetConstraintForNativeQuery(bp, ClassDetails[0].Clazz, false, false,
                                                                                                 true)) +
                                  QueryUtil.GetOrderByClause(bp.Clause);

                using (var content = new ParsiContext())
                {
                    var files = content.File.FromSqlRaw(queryString).OrderBy(x => x.Extension)
                                .ThenByDescending(x => x.Created).IgnoreQueryFilters().ToList();
                    var lstData = files.Select(file => Copier.GetDto(file)).ToList();
                    return(lstData.Count <= 0
                        ? new ServiceResult <object>(new List <FileDto>(), 0)
                        : new ServiceResult <object>(lstData, lstData.Count));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 2
0
 public ActionResult Verify(string id)
 {
     if (string.IsNullOrEmpty(id))
     {
         return(View("_Error", new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError, "کد فعال سازی معتبر نمی باشد")));
     }
     else
     {
         using (var context = new ParsiContext())
         {
             var user = context.Users.Where(p => p.EmailCode == id.Trim()).IgnoreQueryFilters().FirstOrDefault();
             if (user != null)
             {
                 if (user.Deleted != 0)
                 {
                     return(View("_Error", new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError, "اطلاعاتی یافت نشد")));
                 }
                 user.EmailCode = Guid.NewGuid().ToString();
                 user.Active    = true;
                 context.Users.Update(user);
                 context.SaveChanges();
                 return(Redirect("/login"));
             }
             else
             {
                 return(View("_Error", new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError, "کاربر گرامی لینک فعال سازی حساب کاربری شما منقضی شده است . لطفا مجددا در سایت عضو شده و یا از قسمت ارتباط با ما درخواستی مبنی بر فعال سازی حساب کاربری برای مدیر سایت ارسال نمایید")));
             }
         }
     }
 }
Exemplo n.º 3
0
        public ServiceResult <object> ShowRow(BusinessParam bp)
        {
            var  methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";
            long entityId   = 0;

            foreach (var where in bp.Clause.Wheres.Where(where =>
                                                         where.Key.Equals("entityId") && where.Value != null && !where.Value.Equals("")))
            {
                entityId = long.Parse(where.Value);
            }

            try
            {
                if (entityId == 0)
                {
                    return(ExceptionUtil.ExceptionHandler("شناسه مورد نظر یافت نشد",
                                                          ClassDetails[0].Facade + methodName,
                                                          bp.UserInfo));
                }
                using (var content = new ParsiContext())
                {
                    var data = content.AccessGroup.Where(p => p.EntityId == entityId).Include(p => p.CreateUserEntity)
                               .Include(p => p.UpdateUserEntity).Include(p => p.ParentAccessGroupUseCaseActionAccessGroup)
                               .ThenInclude(p => p.CurrentUseCaseAction).ThenInclude(p => p.CurrentAction).IgnoreQueryFilters()
                               .ToList();
                    return(new ServiceResult <object>(Copier.GetDto(data[0]), 1));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 4
0
        public ServiceResult <object> ShowRow(BusinessParam bp)
        {
            var  methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";
            long entityId   = 0;

            foreach (var where in bp.Clause.Wheres.Where(where =>
                                                         where.Key.Equals("entityId") && where.Value != null && !where.Value.Equals("")))
            {
                entityId = long.Parse(where.Value);
            }

            try
            {
                if (entityId == 0)
                {
                    return(ExceptionUtil.ExceptionHandler("شناسه مورد نظر یافت نشد",
                                                          ClassDetails[0].Facade + methodName,
                                                          bp.UserInfo));
                }
                using (var context = new ParsiContext())
                {
                    var person = context.Person.Where(p => p.EntityId == entityId)
                                 .Include(p => p.CurrentFile)
                                 .Include(p => p.CurrentBloodType)
                                 .Include(p => p.CurrentCitizenship)
                                 .Include(p => p.CurrentDisabilityType)
                                 .Include(p => p.CurrentHealthStatus)
                                 .Include(p => p.CurrentHousingSituation)
                                 .Include(p => p.CurrentLifeStatus)
                                 .Include(p => p.CurrentMaritalStatus)
                                 .Include(p => p.CurrentMilitaryServiceStatus)
                                 .Include(p => p.CurrentNationality)
                                 .Include(p => p.CurrentSex)
                                 .Include(p => p.CurrentReligion)
                                 .Include(p => p.CurrentSubReligion)
                                 .Include(p => p.CreateUserEntity)
                                 .Include(p => p.UpdateUserEntity)
                                 .IgnoreQueryFilters()
                                 .ToList();
                    return(person.Count == 0
                        ? new ServiceResult <object>(Enumerator.ErrorCode.NotFound, "رکورد یافت نشد")
                        : new ServiceResult <object>(Copier.GetDto(person[0]), 1));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 5
0
        public ServiceResult <object> ShowRow(BusinessParam bp)
        {
            var  methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";
            long entityId   = 0;

            foreach (var where in bp.Clause.Wheres.Where(where =>
                                                         where.Key.Equals("entityId") && where.Value != null && !where.Value.Equals("")))
            {
                entityId = long.Parse(where.Value);
            }

            try
            {
                if (entityId == 0)
                {
                    return(ExceptionUtil.ExceptionHandler("شناسه مورد نظر یافت نشد",
                                                          ClassDetails[0].Facade + methodName,
                                                          bp.UserInfo));
                }
                using (var context = new ParsiContext())
                {
                    var data = context.Organization.Where(p => p.EntityId == entityId)
                               .Include(p => p.CurrentLogo)
                               .Include(p => p.CurrentOrganizationGrade)
                               .Include(p => p.CurrentOrganizationOwnershipType)
                               .Include(p => p.CurrentOrganizationRoadType)
                               .Include(p => p.CurrentOrganizationStatus)
                               .Include(p => p.CurrentOrganizationType)
                               .Include(p => p.CurrentProvince)
                               .Include(p => p.CurrentCity)
                               .Include(p => p.CurrentOrganization)
                               .Include(p => p.CreateUserEntity)
                               .Include(p => p.UpdateUserEntity)
                               .IgnoreQueryFilters()
                               .ToList();
                    return(data.Count == 0
                        ? new ServiceResult <object>(Enumerator.ErrorCode.NotFound, "رکورد یافت نشد")
                        : new ServiceResult <object>(Copier.GetDto(data[0]), 1));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 6
0
        public ServiceResult <object> GetTotalUseCase(BusinessParam bp, bool getAllData, string search,
                                                      string pageNumber)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                using (var context = new ParsiContext())
                {
                    var useCase = context.UseCase
                                  .Include(p => p.CurrentUseCase)
                                  .Include(p => p.ParentUseCaseUseCaseAction)
                                  .ThenInclude(p => p.CurrentAction)
                                  .ToList();
                    return(new ServiceResult <object>(PrePareToShowInAccessGroup(Copier.GetDto(useCase)), 1));
                }
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 7
0
        public ServiceResult <object> GetAllMenu(BusinessParam bp)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                using (var context = new ParsiContext())
                {
                    var list = new List <MenuDto>();
                    var data = context.Menu.Include(p => p.CurrentUseCase).ToList();
                    foreach (var menu in data)
                    {
                        var usecase = menu.CurrentUseCase.Clazz.ToLower();
                        if (bp.UserInfo.RoleId == DataLayer.Tools.SystemConfig.SystemRoleId)
                        {
                            list.Add(Copier.GetDto(menu));
                        }
                        else if (bp.UserInfo.UseCase.ContainsKey(usecase))
                        {
                            var lst = bp.UserInfo.UseCase[usecase];
                            foreach (var item in lst)
                            {
                                if (item.ToLower() == "showinmenu")
                                {
                                    list.Add(Copier.GetDto(menu));
                                }
                            }
                        }
                    }

                    return(new ServiceResult <object>(list, list.Count));
                }
            }
            catch (Exception ex)
            {
                return(ExceptionUtil.ExceptionHandler(ex, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 8
0
        public ServiceResult <object> Login()
        {
            try
            {
                Users user;
                var   userName = Request.Form["username"].ToString();
                var   password = Request.Form["password"].ToString();
                var   captcha  = Request.Form["captcha"].ToString();
                if (string.IsNullOrEmpty(userName))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "لطفا نام کاربری را وارد نمایید"));
                }
                if (string.IsNullOrEmpty(password))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "لطفا کلمه عبور را وارد نمایید"));
                }
                if (string.IsNullOrEmpty(captcha))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "لطفا کد امنیتی را وارد نمایید"));
                }
                if (!DataLayer.Tools.Captcha.ValidateCaptchaCode(captcha, Request.HttpContext))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError, "کد امنیتی صحیح نمی باشد"));
                }
                using (var unitOfWork = new UnitOfWork())
                {
                    user = unitOfWork.Users.Get(p => p.Username == userName.ToLower().Trim()).FirstOrDefault();
                    if (user != null)
                    {
                        var pas = UserFacade.GetInstance().GetHashPassword(password);
                        if (user.Attempt >= DataLayer.Tools.SystemConfig.MaxAttemptLogin)
                        {
                            user.Attempt = Convert.ToInt16(user.Attempt + 1);
                            unitOfWork.Users.Update(user);
                            unitOfWork.Users.Save();
                            return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                              "حساب کاربری مورد نظر مسدود می باشد"));
                        }

                        if (user.Active == false)
                        {
                            return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                              "حساب کاربری مورد نظر مسدود می باشد"));
                        }
                        if (pas != user.Password)
                        {
                            user.Attempt = Convert.ToInt16(user.Attempt + 1);
                            unitOfWork.Users.Update(user);
                            unitOfWork.Users.Save();
                            return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                              "کاربری با این مشخصات یافت نشد"));
                        }
                    }
                    else
                    {
                        return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                          "کاربری با این مشخصات یافت نشد"));
                    }
                }

                var userInfos = new List <UserInfo>();
                using (var context = new ParsiContext())
                {
                    var userRoles = context.UserRole.Where(p => p.UserId == user.EntityId)
                                    .Include(p => p.CurrentRole)
                                    .Include(p => p.CurrentOrganization)
                                    .ToList();
                    userInfos.AddRange(userRoles.Select(item => new UserInfo
                    {
                        Active           = true,
                        AccessKey        = "",
                        Token            = "",
                        FirstName        = "",
                        LastName         = "",
                        Password         = "",
                        Username         = "",
                        PersonId         = -1,
                        RoleId           = item.RoleId,
                        UserId           = -1,
                        RoleName         = item.CurrentRole.RoleName,
                        OrganizationName = item.CurrentOrganization.Name,
                        OrganizationId   = item.OrganizationId,
                        Picture          = ""
                    }));
                }

                if (userInfos.Count == 0)
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "کاربری با این مشخصات یافت نشد"));
                }
                return(new ServiceResult <object>(userInfos, userInfos.Count));
            }
            catch (Exception e)
            {
                return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError, e.Message));
            }
        }
Exemplo n.º 9
0
        public ServiceResult <object> SelectUserRole([FromBody] UserInfo userInfo)
        {
            if (userInfo.RoleId == DataLayer.Tools.SystemConfig.SystemRoleId)
            {
                var clientIp = Util.GetClientIp(Request);
                if (!DataLayer.Tools.SystemConfig.AdminValidIp.Contains(clientIp))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.AccessDeny,
                                                      $"Admin IP is invalid: {clientIp}"));
                }
            }

            var httpSession = HttpContext.Session;
            var ip          = Util.GetClientIp(Request);

            if (httpSession == null || string.IsNullOrEmpty(httpSession.Id))
            {
                return(new ServiceResult <object>(Enumerator.ErrorCode.BusinessMessage,
                                                  "داده های ارسالی معتبر نمی باشد"));
            }
            var requestedUrl = Request.Headers["referer"].ToString();

            if (requestedUrl == null)
            {
                return(new ServiceResult <object>(Enumerator.ErrorCode.BusinessMessage, "درخواست معتبر نمی باشد"));
            }
            try
            {
                if (string.IsNullOrEmpty(userInfo.Username.Trim()))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "لطفا نام کاربری را وارد نمایید"));
                }
                if (string.IsNullOrEmpty(userInfo.Password.Trim()))
                {
                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "لطفا کلمه عبور را وارد نمایید"));
                }
                var token = UserFacade.GetInstance()
                            .GetHashPassword(Util.GetTimeStamp(DateTime.Now).ToString(CultureInfo.InvariantCulture));

                using (var context = new ParsiContext())
                {
                    var userRole = context.UserRole.Where(p =>
                                                          p.CurrentUsers.Username == userInfo.Username.ToLower().Trim() &&
                                                          p.CurrentUsers.Password ==
                                                          UserFacade.GetInstance().GetHashPassword(userInfo.Password.Trim()) &&
                                                          p.RoleId == userInfo.RoleId &&
                                                          p.OrganizationId == userInfo.OrganizationId)
                                   .Include(p => p.CurrentRole)
                                   .Include(p => p.CurrentOrganization)
                                   .Include(p => p.CurrentUsers)
                                   .ThenInclude(p => p.CurrentPerson)
                                   .ThenInclude(p => p.CurrentFile)
                                   .FirstOrDefault();
                    if (userRole != null)
                    {
                        var info = new UserInfo
                        {
                            Active           = userRole.CurrentUsers.Active,
                            AccessKey        = userRole.OrgAccess,
                            Token            = token,
                            FirstName        = userRole.CurrentUsers.FirstName,
                            LastName         = userRole.CurrentUsers.LastName,
                            Password         = "",
                            Username         = userRole.CurrentUsers.Username,
                            PersonId         = userRole.CurrentUsers.PersonId,
                            RoleId           = userRole.RoleId,
                            UserId           = userRole.UserId,
                            RoleName         = userRole.CurrentRole.RoleName,
                            OrganizationName = userRole.CurrentOrganization.Name,
                            OrganizationId   = userRole.OrganizationId,
                            Timestamp        = Util.GetTimeStamp(
                                DateTime.Now.AddMinutes(
                                    Convert.ToDouble(userRole.CurrentRole.ExpireMinute.ToString()))),
                            Picture = userRole.CurrentUsers.CurrentPerson?.CurrentFile?.Path
                        };
                        info.UseCase = new Dictionary <string, HashSet <string> >();
                        var accessGroup = context.RoleAccessGroup.Where(p => p.Role == info.RoleId)
                                          .Select(p => p.AccessGroup)
                                          .ToList();
                        if (accessGroup.Count > 0)
                        {
                            var data = context.UseCaseActionAccessGroup.Where(p => accessGroup.Contains(p.AccessGroup))
                                       .Include(p => p.CurrentUseCaseAction)
                                       .ThenInclude(p => p.CurrentUseCase)
                                       .Include(p => p.CurrentUseCaseAction)
                                       .ThenInclude(p => p.CurrentAction).ToList();
                            foreach (var item in data)
                            {
                                if (info.UseCase.ContainsKey(item.CurrentUseCaseAction.CurrentUseCase.Clazz.ToLower()))
                                {
                                    var current =
                                        info.UseCase[item.CurrentUseCaseAction.CurrentUseCase.Clazz.ToLower()];
                                    current.Add(item.CurrentUseCaseAction.CurrentAction.ActionEnName);
                                    info.UseCase.Remove(item.CurrentUseCaseAction.CurrentUseCase.Clazz.ToLower());
                                    info.UseCase.Add(item.CurrentUseCaseAction.CurrentUseCase.Clazz.ToLower(), current);
                                }
                                else
                                {
                                    var current = new HashSet <string>();
                                    current.Add(item.CurrentUseCaseAction.CurrentAction.ActionEnName);
                                    info.UseCase.Add(item.CurrentUseCaseAction.CurrentUseCase.Clazz.ToLower(), current);
                                }
                            }
                        }

                        var offset =
                            new DateTimeOffset(
                                DateTime.Now.AddMinutes(
                                    Convert.ToDouble(userRole.CurrentRole.ExpireMinute.ToString())));
                        var option = new MemoryCacheEntryOptions().SetAbsoluteExpiration(offset)
                                     .SetPriority(CacheItemPriority.High);
                        _memoryCache.Set("session_" + info.Username, info, option);

                        var claims = new List <Claim>
                        {
                            new Claim("userId", info.UserId.ToString()),
                            new Claim(ClaimTypes.Name, info.Username),
                            new Claim("username", info.Username),
                            new Claim("firstName", info.FirstName),
                            new Claim("lastName", info.LastName),
                            new Claim("roleName", info.RoleName),
                            new Claim("token", info.Token),
                            new Claim("picture", info.Picture ?? "images/users/avatar.png"),
                            new Claim("IsAdmin", userRole.CurrentUsers.IsAdmin.ToString())
                        };
                        var identity   = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                        var principal  = new ClaimsPrincipal(identity);
                        var properties = new AuthenticationProperties
                        {
                            IsPersistent = userInfo.Remember
                        };
                        HttpContext.SignInAsync(principal, properties);
                        var newUserInfo = new SimpleUserInfo
                        {
                            Token            = info.Token,
                            Username         = info.Username,
                            FirstName        = info.FirstName,
                            LastName         = info.LastName,
                            RoleName         = info.RoleName,
                            OrganizationName = info.OrganizationName,
                            Timestamp        = Util.GetTimeStamp(
                                DateTime.Now.AddMinutes(Convert.ToDouble(userRole.CurrentRole.ExpireMinute.ToString())))
                        };
                        var ticket = _jwtHandlers.Create(new TokenOption
                        {
                            UserInfo      = newUserInfo,
                            ExpireMinutes = userRole.CurrentRole.ExpireMinute,
                            Ip            = ip
                        });
                        newUserInfo.Ticket = ticket.Ticket;
                        return(new ServiceResult <object>(newUserInfo, 1));
                    }

                    return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                      "کاربری با این مشخصات یافت نشد"));
                }
            }
            catch (Exception e)
            {
                return(new ServiceResult <object>(Enumerator.ErrorCode.BusinessMessage,
                                                  "امکان ورود به سایت در حال حاضر میسر نمی باشد"));
            }
        }