コード例 #1
0
        public HttpResponseMessage Post(ConfigItem item)
        {
            //  if (!_orchardServices.Authorizer.Authorize(Permissions.ivAdminTab))
            //      return Request.CreateResponse(HttpStatusCode.Forbidden);

            try
            {
                switch ((string) item.Type)
                {
                    case "member_type":
                        return Request.CreateResponse(HttpStatusCode.OK, _configServices.SaveMemberType(item));
                    case "team":
                        TeamName team = null;
                        return Request.CreateResponse(HttpStatusCode.OK, _configServices.SaveTeamName(item, out team));
                }

                return Request.CreateResponse(HttpStatusCode.BadRequest, "Configuration item does not exist");
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex, string.Empty, null);
                return Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
        }
コード例 #2
0
        public ConfigItem SaveHowOut(ConfigItem newItem, out HowOut howOut)
        {
            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        var item = session.CreateCriteria(typeof(HowOut))
                            .List<HowOut>()
                            .FirstOrDefault(x => x.Name.ToLowerInvariant() == newItem.Name.ToLowerInvariant()) ??
                                   new HowOut { Name = newItem.Name };

                        if (item.Id != 0)
                        {
                            transaction.Rollback();
                            howOut = item;
                            return null;
                        }

                        SetAudit(item);
                        session.SaveOrUpdate(item);
                        transaction.Commit();

                        howOut = item;
                        newItem.Id = item.Id;
                    }
                    catch (Exception ex)
                    {
                        howOut = null;
                        Logger.Log(LogLevel.Error, ex, string.Empty, null);
                        transaction.Rollback();
                    }
                    return newItem;
                }
            }
        }
コード例 #3
0
        public ConfigItem SaveTeamName(ConfigItem newItem, out TeamName team)
        {
            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        var item = session.CreateCriteria(typeof(TeamName))
                            .List<TeamName>()
                            .FirstOrDefault(x => x.Name.ToLowerInvariant() == newItem.Name.ToLowerInvariant()) ??
                                   new TeamName { Name = newItem.Name };

                        if (item.Id != 0)
                        {
                            transaction.Rollback();
                            team = item;
                            return null;
                        }

                        item.Type = newItem.Type == "Opposition" ? (int)TeamType.Opposition : (int)TeamType.Home;
                      
                        SetAudit(item);
                        session.SaveOrUpdate(item);
                        transaction.Commit();

                        team = item;
                        newItem.Id = item.Id;
                    }
                    catch (Exception ex)
                    {
                        team = null;
                        Logger.Log(LogLevel.Error, ex, string.Empty, null);
                        transaction.Rollback();
                    }
                    return newItem;
                }
            }
        }