Пример #1
0
        public async Task <ActionResult> CreateChurch(cm.Church church)
        {
            try
            {
                InitSession();

                church.CreatedByUserId = _session.UserId;

                var json = await _apiProvider.PostItemAsync <cm.Church>(_uri, church);

                var ch = _apiProvider.DeserializeJson <cm.Church>(json);

                if (ch != null)
                {
                    return(Content("Created: " + ch.id.ToString()));
                }
                else
                {
                    return(Content("Error creating church"));
                }
            }
            catch (Exception ex)
            {
                return(Content("Error creating church: " + ex.Message));
            }
        }
Пример #2
0
        public RepositoryActionResult <TeamMetadata> GetMetadata(int churchId, int userId)
        {
            var metadata = new TeamMetadata();

            using (var cn = new SqlConnection(_executor.ConnectionString))
            {
                using (var cmd = new SqlCommand("GetTeamProfileMetadata", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("churchId", churchId));
                    cmd.Parameters.Add(new SqlParameter("userId", userId));

                    cn.Open();

                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            // read enum types
                            while (reader.Read())
                            {
                                var appEnum = new AppEnum();
                                appEnum.ID                = reader.ValueOrDefault <int>("EnumID");
                                appEnum.Desc              = reader.ValueOrDefault <string>("EnumDesc");
                                appEnum.AppEnumTypeID     = reader.ValueOrDefault <int>("EnumTypeID");
                                appEnum.AppEnumTypeName   = reader.ValueOrDefault <string>("EnumTypeName");
                                appEnum.OptionsEnumTypeID = reader.ValueOrDefault <int>("OptionsEnumTypeID");

                                metadata.EnumTypes.Add(appEnum);
                            }

                            // read enums for above enum types
                            reader.NextResult();
                            while (reader.Read())
                            {
                                var appEnum = new AppEnum();
                                appEnum.ID                = reader.ValueOrDefault <int>("EnumID");
                                appEnum.Desc              = reader.ValueOrDefault <string>("EnumDesc");
                                appEnum.AppEnumTypeID     = reader.ValueOrDefault <int>("EnumTypeID");
                                appEnum.AppEnumTypeName   = reader.ValueOrDefault <string>("EnumTypeName");
                                appEnum.OptionsEnumTypeID = reader.ValueOrDefault <int>("OptionsEnumTypeID");

                                metadata.Enums.Add(appEnum);
                            }

                            // read churches
                            reader.NextResult();
                            while (reader.Read())
                            {
                                var church = new c.Church();
                                church.id   = reader.ValueOrDefault <int>("Id");
                                church.Name = reader.ValueOrDefault <string>("Name");

                                metadata.Churches.Add(church);
                            }

                            // read members
                            reader.NextResult();
                            while (reader.Read())
                            {
                                var member = new Core.Models.Members.Member();
                                member.id        = reader.ValueOrDefault <int>("Id");
                                member.FirstName = reader.ValueOrDefault <string>("FirstName");
                                member.LastName  = reader.ValueOrDefault <string>("LastName");

                                metadata.Members.Add(member);
                            }
                        }
                    }
                }
            }

            return(new RepositoryActionResult <TeamMetadata>(metadata, RepositoryActionStatus.Ok));
        }