Ejemplo n.º 1
0
        public IActionResult GetRedirect()
        {
            try
            {
                string       path         = ControllerContext.HttpContext.Request.Path.ToString();
                RedirectPath redirectPath = _businesslogic.GetRedirectPaths(path);

                if (redirectPath == null)
                {
                    return(NotFound(Messages.redirectNotFound));
                }

                if (_businesslogic.ValidateDestination(redirectPath.destination))
                {
                    return(Redirect(redirectPath.destination));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest));
                }
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> ModifyRedirectPath(long id, RedirectPath redirectPath)
        {
            if (id != redirectPath.Id)
            {
                return(false);
            }

            _context.Entry(redirectPath).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RedirectPathExists(id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <RedirectPath> AddRedirectPath(RedirectPath redirectPath)
        {
            if (!ValidateDestination(redirectPath.destination) || !ValidatePath(redirectPath.path) || GetRedirectPaths(redirectPath.path) != null || GetRedirectPaths(redirectPath.Id) != null)
            {
                return(null);
            }
            else
            {
                _context.RedirectPaths.Add(redirectPath);
                await _context.SaveChangesAsync();
            }

            return(redirectPath);
        }
Ejemplo n.º 4
0
        public RedirectPath Create(RedirectPath model)
        {
            try
            {
                this.Context.RedirectPath.Add(model);
                this.Context.SaveChanges();

                return(model);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
                throw new Exception("DB error", ex.InnerException);
            }
        }
Ejemplo n.º 5
0
        // 页面初始化
        protected virtual void Page_Init(object sender, EventArgs e)
        {
            string path = Request.Url.LocalPath.ToLower();

            if (path.Contains(RedirectPath.ToLower()))
            {
                return;
            }
            if (path.Contains(CheckPath.ToLower()))
            {
                if (Session[SessionName.ToLower()] == null)
                {
                    Response.Redirect("~" + RedirectPath.ToLower());
                    return;
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <RedirectPath> > PostRedirectPath(RedirectPath redirectPath)
        {
            try
            {
                redirectPath = await _businesslogic.AddRedirectPath(redirectPath);

                if (redirectPath == null)
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest));
                }
                return(CreatedAtAction(nameof(GetRedirectPath), new { id = redirectPath.Id }, redirectPath));
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 7
0
        public async Task <ActionResult <RedirectPath> > GetRedirectPath(long id)
        {
            try
            {
                RedirectPath redirectPath = _businesslogic.GetRedirectPaths(id);

                if (redirectPath == null)
                {
                    return(NotFound(Messages.redirectNotFound));
                }

                return(redirectPath);
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutRedirectPath(long id, RedirectPath redirectPath)
        {
            try
            {
                bool modifySuccess = await _businesslogic.ModifyRedirectPath(id, redirectPath);

                if (!modifySuccess)
                {
                    return(NotFound(Messages.redirectNotFound));
                }
                else
                {
                    return(NoContent());
                }
            }
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }