예제 #1
0
        /// <summary>
        /// Creates a new file entry for the specified event, from the given user account. The file is also saved to the disk assets.
        /// </summary>
        public Entry CreateFileEntry(Event e, UserAccount user, IFormFile file, IWebHostEnvironment environment)
        {
            Entry entry = new Entry
            {
                Event      = e,
                Author     = user,
                EntryType  = EntryType.File,
                SubmitDate = DateTime.UtcNow
            };

            DisplayIDProvider.InjectDisplayId(entry);

            entry.Content = $"{entry.DisplayID}{Path.GetExtension(file.FileName)}";

            context.Entries.Add(entry);
            context.SaveChanges();

            string absoluteEntryPath = entry.GetAbsoluteUrl(environment);

            // Ensure that the directory exists
            Directory.CreateDirectory(Path.GetDirectoryName(absoluteEntryPath));

            using (var localFile = File.OpenWrite(absoluteEntryPath))
                using (var uploadedFile = file.OpenReadStream())
                {
                    uploadedFile.CopyTo(localFile);
                }

            return(entry);
        }
예제 #2
0
        /// <summary>
        /// Creates an event with the given user specified as host.
        /// </summary>
        public Event CreateEvent(Event e, UserAccount host)
        {
            DisplayIDProvider.InjectDisplayId(e);

            context.Events.Add(e);
            context.SaveChanges();

            RegisterUserAsHost(host, e);

            return(e);
        }
예제 #3
0
        /// <summary>
        /// Creates a new user account with the specified username.
        /// </summary>
        public UserAccount NewUser(string username)
        {
            UserAccount user = new UserAccount()
            {
                Username    = username,
                Permissions = GlobalPermissions.Default,
                JoinDate    = DateTime.UtcNow
            };

            DisplayIDProvider.InjectDisplayId(user);

            _context.UserAccounts.Add(user);
            _context.SaveChanges();

            return(user);
        }
예제 #4
0
        /// <summary>
        /// Creates a new entry for the specified event, from the given user account.
        /// <para>Note that this method only creates the database entry.</para>
        /// </summary>
        public Entry CreateEntry(Event ev, UserAccount user, EntryType type, string content)
        {
            Entry entry = new Entry
            {
                Event      = ev,
                Author     = user,
                EntryType  = type,
                Content    = content,
                SubmitDate = DateTime.UtcNow
            };

            DisplayIDProvider.InjectDisplayId(entry);

            context.Entries.Add(entry);
            context.SaveChanges();

            return(entry);
        }