コード例 #1
0
        public async Task <ActionResult <List <ImportPost> > > UploadXl()
        {
            var retVal = new List <ImportPost>();
            var form   = Request.Form;

            long pId  = Convert.ToInt64(form["personId"].ToString());
            long pmId = Convert.ToInt64(form["personMapId"].ToString());

            foreach (IFormFile file in form.Files)
            {
                var stream = new MemoryStream();

                await file.CopyToAsync(stream);

                var sheet = new ImportPost()
                {
                    PersonMapId = pmId,
                    PersonId    = pId,
                    FileName    = file.FileName,
                    FileLength  = file.Length,
                    Stream      = stream
                };
                try
                {
                    retVal.Add(await _service.ImportSheet(sheet));
                }
                catch (Exception ex)
                {
                    var nw = ex.Message;
                }
            }

            return(retVal);
        }
コード例 #2
0
        public string AddPost(ImportPost import, string previousUrl, bool removeDuplicate)
        {
            Security.ImpersonateUser(AuthenticationHeader.Username, AuthenticationHeader.Password);

            if (!Security.IsAuthenticated)
            {
                throw new InvalidOperationException("Wrong credentials");
            }
            if (!Security.IsAuthorizedTo(Rights.CreateNewPosts))
            {
                throw new InvalidOperationException("Insufficient rights to create a new post");
            }

            if (removeDuplicate && !Post.IsTitleUnique(import.Title))
            {
                // Search for matching post (by date and title) and delete it
                foreach (var temp in
                         Post.GetPostsByDate(import.PostDate.AddDays(-2), import.PostDate.AddDays(2)).Where(
                             temp => temp.Title == import.Title))
                {
                    temp.Delete();
                    temp.Import();
                }
            }

            var post = new Post
            {
                Title        = import.Title,
                Author       = import.Author,
                DateCreated  = import.PostDate,
                DateModified = import.PostDate,
                Content      = import.Content,
                Description  = import.Description,
                IsPublished  = import.Publish
            };

            // TODO: Save Previous Url?
            AddCategories(import.Categories, post);

            // Tag Support:
            // No tags. Use categories.
            post.Tags.AddRange(import.Tags.Count == 0 ? import.Categories : import.Tags);

            post.Import();

            return(post.Id.ToString());
        }
コード例 #3
0
        public string AddPost(ImportPost import, string previousUrl, bool removeDuplicate)
        {
            Security.ImpersonateUser(AuthenticationHeader.Username, AuthenticationHeader.Password);

            if (!Security.IsAuthenticated)
            {
                throw new InvalidOperationException("Wrong credentials");
            }
            if (!Security.IsAuthorizedTo(Rights.CreateNewPosts))
            {
                throw new InvalidOperationException("Insufficient rights to create a new post");
            }

            if (removeDuplicate && !Post.IsTitleUnique(import.Title))
            {
                // Search for matching post (by date and title) and delete it
                foreach (var temp in
                    Post.GetPostsByDate(import.PostDate.AddDays(-2), import.PostDate.AddDays(2)).Where(
                        temp => temp.Title == import.Title))
                {
                    temp.Delete();
                    temp.Import();
                }
            }

            var post = new Post
                {
                    Title = import.Title,
                    Author = import.Author,
                    DateCreated = import.PostDate,
                    DateModified = import.PostDate,
                    Content = import.Content,
                    Description = import.Description,
                    IsPublished = import.Publish
                };

            // TODO: Save Previous Url?
            AddCategories(import.Categories, post);

            // Tag Support:
            // No tags. Use categories. 
            post.Tags.AddRange(import.Tags.Count == 0 ? import.Categories : import.Tags);

            post.Import();

            return post.Id.ToString();
        }