Ejemplo n.º 1
0
        public System.Collections.Generic.IList <EventoEN> ReadAllDefault(int first, int size, NHibernate.ISession session)
        {
            System.Collections.Generic.IList <EventoEN> result = null;
            try
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    if (size > 0)
                    {
                        result = session.CreateCriteria(typeof(EventoEN)).
                                 SetFirstResult(first).SetMaxResults(size).List <EventoEN>();
                    }
                    else
                    {
                        result = session.CreateCriteria(typeof(EventoEN)).List <EventoEN>();
                    }
                }
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is NuevoInmueblateGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new NuevoInmueblateGenNHibernate.Exceptions.DataLayerException("Error in EventoCAD.", ex);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// DbService.getAll<User>();
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>

        public static ICollection <T> GetAll <T>()
        {
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                return(session.CreateCriteria(typeof(T)).List <T>());
            }
        }
Ejemplo n.º 3
0
        private async Task <IActionResult> Remove <T>(int id) where T : class
        {
            try

            {
                using (NHibernate.ISession session = sessionFactory.OpenSession())
                    using (var transaction = session.BeginTransaction())
                    {
                        //DigitalOutputGroup s;s.
                        var @object = await session.CreateCriteria <T>().Add(Restrictions.Eq("Id", id)).UniqueResultAsync <T>();

                        if (@object == null)
                        {
                            return(BadRequest(ApiResult.BadRequest($"대상 ID {id}가 존재하지 않습니다")));
                        }
                        await session.DeleteAsync(@object);

                        await transaction.CommitAsync();

                        return(Ok(ApiResult.OK_200));
                    }
            }
            catch (Exception ex)
            {
                return(BadRequest(ApiResult.BadRequest(ex.Message)));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据查询条件创建Criteria
        /// </summary>
        /// <param name="session"></param>
        /// <param name="searchExpression"></param>
        /// <param name="searchOrders"></param>
        /// <param name="hasCollection"></param>
        /// <returns></returns>
        public static NHibernate.ICriteria CreateCriteria(NHibernate.ISession session, ISearchExpression searchExpression,
                                                          IList <ISearchOrder> searchOrders, ref bool hasCollection)
        {
            hasCollection = false;
            int paramCnt = 0;

            NHibernate.ICriteria           criteria = session.CreateCriteria(typeof(T), "Current");
            Dictionary <string, ICriteria> aliases  = new Dictionary <string, ICriteria>();

            aliases.Add("Current", criteria);

            NHibernate.Criterion.ICriterion criterion = GetCriterion(session.SessionFactory, ref criteria, aliases, searchExpression, ref hasCollection, ref paramCnt);
            if (criterion != null)
            {
                criteria.Add(criterion);
            }
            if (paramCnt > 2100)
            {
                throw new NotSupportedException("您输入的参数过多,系统最多只支持2100个参数!");
            }

            if (searchOrders != null)
            {
                foreach (ISearchOrder so in searchOrders)
                {
                    criteria.AddOrder(GetOrder(ref criteria, aliases, so));
                }
            }

            return(aliases["Current"]);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Save session factory statistics
        /// </summary>
        /// <param name="UUID"></param>
        /// <returns>Session factory</returns>
        public NHibernateProfiler.Common.Entity.Statistics.SessionFactory GetSessionFactoryStatistics(
            string UUID)
        {
            this.c_currentSessionFactoryStatisticsSession = this.c_sessionFactory.OpenSession();

            return c_currentSessionFactoryStatisticsSession.CreateCriteria<NHibernateProfiler.Common.Entity.Statistics.SessionFactory>()
                .Add(NHibernate.Criterion.Expression.Eq("UUID", UUID))
                .UniqueResult<NHibernateProfiler.Common.Entity.Statistics.SessionFactory>();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Save session factory statistics
        /// </summary>
        /// <param name="UUID"></param>
        /// <returns>Session factory</returns>
        public NHibernateProfiler.Common.Entity.Statistics.SessionFactory GetSessionFactoryStatistics(
            string UUID)
        {
            this.c_currentSessionFactoryStatisticsSession = this.c_sessionFactory.OpenSession();

            return(c_currentSessionFactoryStatisticsSession.CreateCriteria <NHibernateProfiler.Common.Entity.Statistics.SessionFactory>()
                   .Add(NHibernate.Criterion.Expression.Eq("UUID", UUID))
                   .UniqueResult <NHibernateProfiler.Common.Entity.Statistics.SessionFactory>());
        }
Ejemplo n.º 7
0
        public ICollection <GroupCampaign> GetAllAccount(GroupCampaign groupCamp)
        {
            ICollection <GroupCampaign> iCol = null;

            try
            {
                using (NHibernate.ISession session = SessionFactory.GetNewSession())
                {
                    iCol = session.CreateCriteria(typeof(GroupCampaign)).List <GroupCampaign>();
                }
            }
            catch (Exception ex)
            {
                GlobusLogHelper.log.Error("Error : " + ex.StackTrace);
            }
            return(iCol);
        }
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> SignonContractor([FromBody] AggregatorRegistModelBase model)
        {
            //TransactionScope trans_scope = new TransactionScope(System.Transactions.TransactionScopeAsyncFlowOption.Enabled);
            var trans_scope = await accountEF.Database.BeginTransactionAsync();

            try

            {
                if (ModelState.IsValid)
                {
                    using (NHibernate.ISession session = _accountContext.SessionFactory.OpenSession())
                        using (ITransaction trans = session.BeginTransaction(System.Data.IsolationLevel.ReadCommitted))
                        {
                            AggregatorGroup aggregatorGroup = await session.GetAsync <AggregatorGroup>(model.AggregatorGroupId);

                            if (aggregatorGroup == null)
                            {
                                if (model.Type == RegisterType.Contrator)
                                {
                                    IdentityError  error   = (_userManager.ErrorDescriber as LocalizedIdentityErrorDescriber).AggregatorNotFounded(model.AggregatorGroupId);
                                    IdentityResult _result = IdentityResult.Failed(error);
                                    return(base.BadRequest(new { Result = _result }));
                                }
                                else
                                {
                                    var groups = await session.CreateCriteria <AggregatorGroup>()
                                                 .Add(Restrictions.Eq("AggName", model.Company))
                                                 .ListAsync <AggregatorGroup>();

                                    aggregatorGroup = groups.FirstOrDefault();
                                    if (aggregatorGroup == null)
                                    {
                                        aggregatorGroup                = new AggregatorGroup();
                                        aggregatorGroup.ID             = Guid.NewGuid().ToString();
                                        aggregatorGroup.AggName        = model.Company;
                                        aggregatorGroup.Representation = "";
                                        aggregatorGroup.Address        = model.Address;
                                        aggregatorGroup.CreateDT       = DateTime.Now;
                                        aggregatorGroup.PhoneNumber    = model.PhoneNumber;
                                        await session.SaveAsync(aggregatorGroup);
                                    }
                                }
                            }


                            var user = CreateUserAccount(model);

                            JObject obj    = JObject.FromObject(user);
                            var     result = await _userManager.CreateAsync(user, model.Password);

                            //result.Errors
                            if (result.Succeeded)
                            {
                                RegisterAccount(session, user, model.AggregatorGroupId);
                                RegisterFileRepositary  registerModel           = RegisterFile(session, user.Id, model.RegisterFilename, model.RegisterFilebase64);
                                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                                await Publisher.PublishMessageAsync(obj.ToString(), cancellationTokenSource.Token);

                                logger.LogInformation($"회원 가입 성공: {obj}");
                                if (model.NotifyEmail)
                                {
                                    string email_contents = htmlGenerator.GenerateHtml("NotifyEmail.html",
                                                                                       new
                                    {
                                        Name       = $"{user.FirstName} {user.LastName}",
                                        Company    = model.Company,
                                        Email      = model.Email,
                                        Phone      = model.PhoneNumber,
                                        Address    = model.Address,
                                        Aggregator = aggregatorGroup.AggName
                                    });

                                    string sender = "PEIU 운영팀";
                                    string target = "";

                                    List <string> supervisor_emails = (await _userManager.GetUsersInRoleAsync(UserRoleTypes.Supervisor)).Select(x => x.Email).ToList();
                                    if (model.Type == RegisterType.Aggregator)
                                    {
                                        target = "중개거래사업자";
                                    }
                                    else if (model.Type == RegisterType.Contrator)
                                    {
                                        target = "발전사업자";
                                        var agg_result = await session.CreateCriteria <VwAggregatoruser>()
                                                         .Add(Restrictions.Eq("AggGroupId", model.AggregatorGroupId))
                                                         .ListAsync <VwAggregatoruser>();

                                        supervisor_emails.AddRange(agg_result.Select(x => x.Email));

                                        //targetEmailUsers = await _userManager.GetUsersInRoleAsync(UserRoleTypes.Aggregator);
                                        //targetEmailUsers = targetEmailUsers.Where(x=>x.agg)
                                    }
                                    else if (model.Type == RegisterType.Supervisor)
                                    {
                                        target = "관리자";
                                    }

                                    //var aggregator_account_users = await _userManager.GetUsersInRoleAsync(UserRoleTypes.Supervisor);
                                    await _emailSender.SendEmailAsync(sender, $"새로운 {target} 가입이 요청되었습니다", email_contents, registerModel, supervisor_emails.ToArray());

                                    logger.LogInformation($"가입 알림 메일 전송: {string.Join(", ", supervisor_emails)}");
                                }
                                //throw new Exception();
                                await trans.CommitAsync();

                                //trans.Commit();
                                trans_scope.Commit();
                                return(Ok(new { Result = result }));
                            }
                            else
                            {
                                trans_scope.Dispose();
                                return(BadRequest(new { Result = result }));
                            }
                        }
                }
                else
                {
                    trans_scope.Dispose();
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                trans_scope.Dispose();
                logger.LogError(ex, ex.Message);
                return(BadRequest());
            }
        }