Ejemplo n.º 1
0
        internal bool Update(IConnectionHandler connectionHandler, IConnectionHandler securityConnection, Security.DataStructure.User user1, System.Web.HttpPostedFileBase file, List <Guid> list)
        {
            var transactionalFacade = SecurityComponent.Instance.UserTransactionalFacade(securityConnection);

            if (!transactionalFacade.Update(user1, file))
            {
                throw new Exception("خطایی در ذخیره کاربر وجود دارد");
            }
            foreach (var guid in list)
            {
                var user = this.Get(connectionHandler, guid, user1.Id);
                if (user == null)
                {
                    var securityUser = new SecurityUser {
                        CongressId = guid, UserId = user1.Id
                    };
                    if (!this.Insert(connectionHandler, securityUser))
                    {
                        throw new Exception("خطایی در ذخیره کاربر وجود دارد");
                    }
                }
            }
            var byFilter = this.Where(connectionHandler, x => x.UserId == user1.Id);

            foreach (var securityUser in byFilter)
            {
                if (list.All(x => x != securityUser.CongressId))
                {
                    if (!this.Delete(connectionHandler, securityUser.CongressId, securityUser.UserId))
                    {
                        throw new Exception("خطایی در حذف کاربر وجود دارد");
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        internal bool Insert(IConnectionHandler connectionHandler, IConnectionHandler securityConnection, Security.DataStructure.User user1, System.Web.HttpPostedFileBase file, List <Guid> list)
        {
            var transactionalFacade = SecurityComponent.Instance.UserTransactionalFacade(securityConnection);
            var firstOrDefault      = transactionalFacade.FirstOrDefault(x => x.Username.ToLower() == user1.Username.ToLower());

            if (firstOrDefault == null)
            {
                if (!transactionalFacade.Insert(user1, file))
                {
                    throw new Exception("خطایی در ذخیره کاربر وجود دارد");
                }
            }
            else
            {
                user1.Id = firstOrDefault.Id;
            }

            foreach (var guid in list)
            {
                var securityUser = new SecurityUser {
                    CongressId = guid, UserId = user1.Id
                };
                if (!this.Insert(connectionHandler, securityUser))
                {
                    throw new Exception("خطایی در ذخیره کاربر وجود دارد");
                }
            }
            var userOperation = new UserOperation()
            {
                UserId = user1.Id, OperationId = Common.Constants.OperationId.CongressOperationId
            };
            var userOperationTransactionalFacade = SecurityComponent.Instance.UserOperationTransactionalFacade(securityConnection);

            if (!userOperationTransactionalFacade.Any(x => x.UserId == user1.Id && x.OperationId == Common.Constants.OperationId.CongressOperationId))
            {
                if (!userOperationTransactionalFacade.Insert(userOperation))
                {
                    throw new Exception("خطایی در ذخیره کاربر وجود دارد");
                }
            }

            return(true);
        }