Exemple #1
0
        public async Task <Shortcut> InsertAsync(string alias, string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            Shortcut shortcut = new Shortcut
            {
                Alias = alias
            };

            if (url.Length <= 80)
            {
                shortcut.Redirect = new Redirect
                {
                    Url      = url,
                    Shortcut = shortcut,
                };
                shortcut.RedirectExtended = null;
            }
            else if (url.Length <= 1000)
            {
                shortcut.RedirectExtended = new RedirectExtended
                {
                    Url      = url,
                    Shortcut = shortcut,
                };
                shortcut.Redirect = null;
            }
            else
            {
                return(null);
            }

            await _shortcutRepository.InsertAsync(shortcut);

            return(shortcut);
        }