Пример #1
0
        /// <summary>
        /// Adds File to Database
        /// </summary>
        /// <param name="info"></param>
        /// <param name="hierarchyId">Folder Directory of user uploading file</param>
        /// <returns></returns>
        public Guid AddResource(ResourceInfo info, string hierarchyId, EnumPostType postType)
        {
            try
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter("[resource].[AddFileByParentId]", AppConfigManager.ConnectionString))
                {
                    info.ResourceId = Guid.NewGuid();
                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                    adapter.SelectCommand.Parameters.AddWithValue("@ResourceId", info.ResourceId);
                    var nodeParam = adapter.SelectCommand.Parameters.Add("@UserHierarchyId", SqlDbType.Udt);
                    nodeParam.Value = SqlHierarchyId.Parse(hierarchyId);
                    nodeParam.UdtTypeName = "HierarchyId";
                    string extn = CodeHelper.CustomPicFileExtension;

                    switch (postType)
                    {
                        case EnumPostType.None:
                            break;
                        case EnumPostType.Picture:
                            extn = CodeHelper.CustomPicFileExtension;
                            break;
                        case EnumPostType.Video:
                            extn = CodeHelper.CustomVideoFileExtension;
                            break;
                        case EnumPostType.Audio:
                            extn = CodeHelper.CustomAudioFileExtension;
                            break;
                        default:
                            break;
                    }

                    adapter.SelectCommand.Parameters.AddWithValue("@FileExtension", extn);
                    adapter.SelectCommand.Parameters.AddWithValue("@FileData", info.Data);

                    adapter.SelectCommand.Connection.Open();
                    adapter.SelectCommand.ExecuteNonQuery();
                    adapter.SelectCommand.Connection.Close();
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                throw new Exception(CodeHelper.UnableToAddFile);
            }

            return info.ResourceId;
        }
Пример #2
0
        public Guid?[] AddPostImages(ResourceInfo resourceInfo1, ResourceInfo resourceInfo2, string hierarchyId, EnumPostType postType)
        {
            try
            {
                ResourceManager mgr = new ResourceManager();
                Guid resourceId1 = mgr.AddResource(resourceInfo1, hierarchyId, postType);
                Guid? resourceId2 = null;
                if (resourceInfo2 != null && !String.IsNullOrWhiteSpace(resourceInfo2.DataUrl))
                    resourceId2 = mgr.AddResource(resourceInfo2, hierarchyId, postType);

                return new Guid?[] { resourceId1, resourceId2 };
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                throw new Exception(CodeHelper.UnableToAddFile);
            }
        }
Пример #3
0
        // Add new post
        public long AddPost(PostInfo info, Guid? Image1Idf, Guid? Image2Idf, EnumPostType postType, string hierarchyId)
        {
            try
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter("[posts].[AddPost]", AppConfigManager.ConnectionString))
                {
                    adapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                    adapter.SelectCommand.Parameters.AddWithValue("@UserIdf", info.UserIdf);
                    adapter.SelectCommand.Parameters.AddWithValue("@Title", info.Title);
                    adapter.SelectCommand.Parameters.AddWithValue("@EndDate", info.EndDate);
                    adapter.SelectCommand.Parameters.AddWithValue("@Caption1", info.Caption1);
                    adapter.SelectCommand.Parameters.AddWithValue("@Caption2", info.Caption2);
                    adapter.SelectCommand.Parameters.AddWithValue("@Img1Idf", Image1Idf);
                    adapter.SelectCommand.Parameters.AddWithValue("@Img2Idf", Image2Idf);
                    adapter.SelectCommand.Parameters.AddWithValue("@NumberOfSubscribers", info.NumberOfSubscribers);
                    adapter.SelectCommand.Parameters.AddWithValue("@isPublic", info.IsPublic);
                    adapter.SelectCommand.Parameters.AddWithValue("@toContacts", info.ToContacts);
                    adapter.SelectCommand.Parameters.AddWithValue("@toSelectedContacts", info.ToSelectedContacts);
                    adapter.SelectCommand.Parameters.AddWithValue("@TerritoryId", info.IsGlobal ? (int?)null : info.TerritoryId);
                    adapter.SelectCommand.Parameters.AddWithValue("@isGlobal", info.IsGlobal);
                    adapter.SelectCommand.Parameters.AddWithValue("@TypeId", (int)postType);
                    adapter.SelectCommand.Parameters.AddWithValue("@CategoryId", info.CategoryId);
                    var nodeParam = adapter.SelectCommand.Parameters.Add("@FolderPath", SqlDbType.Udt);
                    nodeParam.Value = SqlHierarchyId.Parse(hierarchyId);
                    nodeParam.UdtTypeName = "HierarchyId";

                    // Gets postId of Inserted post
                    adapter.SelectCommand.Connection.Open();
                    var postId = adapter.SelectCommand.ExecuteScalar();
                    adapter.SelectCommand.Connection.Close();
                    return Convert.ToInt64(postId);
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                throw new Exception(CodeHelper.UnableToAddPost);
            }
        }