示例#1
0
partial         void AfterUpdateData(EmploymentStudentVisitLog e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
示例#2
0
 protected void AssertIsView(ActionResult result, string viewName)
 {
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(typeof(ViewResult), result);
     var view = (ViewResult)result;
     Assert.AreEqual(viewName, view.ViewName);
 }
 public static void HasError(ActionResult result, int index, string field, string message)
 {
     var view = (ViewResult)result;
     var error = ((IList<ValidationError>)view.ViewData["ValidationErrors"])[index];
     Assert.Equal(field, error.Field);
     Assert.Equal(message, error.Message);
 }
        public static void IsFile(ActionResult actionResult, string fileName)
        {
            GenericAssert.InstanceOf<FileStreamResult>(actionResult);

            var fileStreamResult = (FileStreamResult)actionResult;
            GenericAssert.AreEqual(fileName, fileStreamResult.FileDownloadName);
        }
        public static void IsRedirect(ActionResult actionResult, string targetUrl)
        {
            GenericAssert.InstanceOf<RedirectResult>(actionResult);

            var redirectResult = (RedirectResult)actionResult;
            GenericAssert.AreEqual(targetUrl, redirectResult.Url);
        }
 public Form(ActionResult result) : base(result)
 {
     _routeValues = new RouteValueDictionary();
     _result = result;
     _formMethod = System.Web.Mvc.FormMethod.Post;
     _actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
示例#7
0
 private bool ValidateUserNamePasswordLogin(LoginModel login, string redirectUrl, out ActionResult redirect)
 {
     try
     {
         if (authProvider.Authenticate(login.Name, login.UserName, login.Password))
         {
             redirect = Redirect(redirectUrl);
             return true;
         }
     }
     catch (InvalidCredentialsException)
     {
         ModelState.AddModelError("", "Invalid user name or password");
         RedirectToAction("Fail");
     }
     catch (UserNotAuthenticatedException)
     {
         ModelState.AddModelError("", "User could not be identified");
         RedirectToAction("Fail");
     }
     catch (UnsupportedAuthenticationType)
     {
         ModelState.AddModelError("", "Authentication mode not supported");
         RedirectToAction("Fail");
     }
     catch (Exception)
     {
         ModelState.AddModelError("", "Something went wrong");
         redirect = View();
         return true;
     }
     redirect = View();
     return false;
 }
示例#8
0
        private bool IsValid(int itemId, out ContentItem item, out ActionResult invalidResult)
        {
            if (_orchardServices.WorkContext.CurrentUser == null || !_orchardServices.Authorizer.Authorize(Permissions.WatchItems))
            {
                invalidResult = new HttpUnauthorizedResult();
                item = null;
                return false;
            }

            item = _orchardServices.ContentManager.Get(itemId);

            if (item == null)
            {
                invalidResult = HttpNotFound();
                return false;
            }

            if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent))
            {
                invalidResult = new HttpUnauthorizedResult();
                return false;
            }

            if (!item.Has<WatchablePart>())
            {
                invalidResult = HttpNotFound();
                return false;
            }

            invalidResult = null;
            return true;
        }
示例#9
0
        /// <summary>
        /// Renders an action result to a string. This is done by creating a fake http context
        /// and response objects and have that response send the data to a string builder
        /// instead of the browser.
        /// </summary>
        /// <param name="result">The action result to be rendered to string.</param>
        /// <returns>The data rendered by the given action result.</returns>
        protected string RenderActionResultToString(ActionResult result)
        {
            // Create memory writer.
            var sb = new StringBuilder();
            var memWriter = new StringWriter(sb);

            // Create fake http context to render the view.
            var fakeResponse = new HttpResponse(memWriter);
            var fakeContext = new HttpContext(System.Web.HttpContext.Current.Request, fakeResponse);
            var fakeControllerContext = new ControllerContext(
                new HttpContextWrapper(fakeContext),
                this.ControllerContext.RouteData,
                this.ControllerContext.Controller);
            var oldContext = System.Web.HttpContext.Current;
            System.Web.HttpContext.Current = fakeContext;

            // Render the view.
            result.ExecuteResult(fakeControllerContext);

            // Restore data.
            System.Web.HttpContext.Current = oldContext;

            // Flush memory and return output.
            memWriter.Flush();
            return sb.ToString();
        }
示例#10
0
partial         void AfterUpdateData(StudentChangeClazzLog e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
        /// <summary>
        /// Creates a Navigation action link inside an li tag that highlights based on which page you're on.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper.</param>
        /// <param name="linkText">The link text.</param>
        /// <param name="actionResult">The action result.</param>
        /// <returns></returns>
        public static MvcHtmlString NavActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult actionResult)
        {
            var result = actionResult.GetT4MVCResult();

            var li = new TagBuilder("li");

            // create anchor tag
            var anchor = HtmlHelper.GenerateLink(
                    htmlHelper.ViewContext.RequestContext,
                    RouteTable.Routes,
                    linkText,
                    "",
                    result.Action,
                    result.Controller,
                    result.RouteValueDictionary,
                    null);

            // add anchor tag to li tag
            li.InnerHtml = anchor;

            // get the route data
            var controller = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue as string;
            var action = htmlHelper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue as string;
            if (result.Action == action && result.Controller == controller)
            {
                li.MergeAttribute("class", "active");
            }

            return MvcHtmlString.Create(li.ToString());
        }
示例#12
0
        private static Route CreateRoute(string url, ActionResult result, object defaults, object constraints, string[] namespaces)
        {
            // Start by adding the default values from the anonymous object (if any)
            var routeValues = new RouteValueDictionary(defaults);

            // Then add the Controller/SecureAction names and the parameters from the call
            foreach (var pair in result.GetRouteValueDictionary())
            {
                routeValues.Add(pair.Key, pair.Value);
            }

            var routeConstraints = new RouteValueDictionary(constraints);

            // Create and add the route
            var route = new Route(url, routeValues, routeConstraints, new MvcRouteHandler());

            route.DataTokens = new RouteValueDictionary();

            if (namespaces != null && namespaces.Length > 0)
            {
                route.DataTokens["Namespaces"] = namespaces;
            }

            return(route);
        }
示例#13
0
partial         void AfterUpdateData(StudentHomeVisitRecord e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
示例#14
0
        public void TestAddInvoice()
        {
            InvoiceController ic = new InvoiceController();

            //load first customer by calling DBcontext
            InvoiceDB db = new InvoiceDB();
            Customer  c  = db.Customers.First();

            ((IObjectContextAdapter)db).ObjectContext.Detach(c); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext
            Assert.NotNull(c);

            Invoice i = new Invoice();

            i.CustomerID        = c.CustomerID;
            i.Customer          = c;
            i.AdvancePaymentTax = 10;
            i.Notes             = "Invoice notes";
            i.TimeStamp         = DateTime.Now;
            i.DueDate           = DateTime.Now.AddDays(90);
            i.Paid = false;
            i.Name = "Test invoice";

            System.Web.Mvc.ActionResult resultAdd = ic.Create(i);

            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAdd);
        }
 public BootstrapActionLink(HtmlHelper html, string linkText, ActionResult result)
 {
     this.html = html;
     this._linkText = linkText;
     this._result = result;
     this._actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
示例#16
0
 private static void AssertStatusCodeResult(ActionResult result, int statusCode, string statusDesc)
 {
     Assert.IsType<HttpStatusCodeWithBodyResult>(result);
     var httpStatus = (HttpStatusCodeWithBodyResult)result;
     Assert.Equal(statusCode, httpStatus.StatusCode);
     Assert.Equal(statusDesc, httpStatus.StatusDescription);
 }
示例#17
0
partial         void BeforeDeleteData(int id, ref ActionResult ar)
        {
            ISalesTeamMemberService ms = new SalesTeamMemberService(new SysContext { CurrentUser = AppContext.CurrentUser },this.Service.Db);
            if (ms.FindBySalesTeamId(id).Count > 0) {
                ar = this.Json(new AjaxOperationResult { Successful = false, Message = "必须删除所有成员之后才能删除招生小组。" });
            }
        }
 public static string GetUrl(this HtmlHelper html, ActionResult actionResult)
 {
     if (actionResult == null) throw new ArgumentNullException("actionResult");
     RouteValueDictionary routeValueDictionary = actionResult.GetRouteValueDictionary();
     return UrlHelper.GenerateUrl(null, null, null, routeValueDictionary, html.RouteCollection,
                           html.ViewContext.RequestContext, false);
 }
示例#19
0
partial         void AfterAddData(Clazz e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
示例#20
0
        public static MvcHtmlString ActionImage(this HtmlHelper html, ActionResult action, Image image, int size = 100, string genericPath = null)
        {
            string path;
            string alt;
            if (image != null)
            {
                path = image.Url;
                alt = image.AltText;
            }
            else
            {
                path = genericPath;
                alt = string.Empty;
            }

            var url = new UrlHelper(html.ViewContext.RequestContext);

            // build the <img> tag
            var imgBuilder = new TagBuilder("img");
            imgBuilder.MergeAttribute("src", url.Content(path));
            imgBuilder.MergeAttribute("alt", alt);
            imgBuilder.MergeAttribute("height", size.ToString());
            string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);

            // build the <a> tag
            var anchorBuilder = new TagBuilder("a");
            anchorBuilder.MergeAttribute("href", url.Action(action));
            anchorBuilder.InnerHtml = imgHtml; // include the <img> tag inside
            string anchorHtml = anchorBuilder.ToString(TagRenderMode.Normal);

            return MvcHtmlString.Create(anchorHtml);
        }
        public ActionResult CreateResult(ControllerContext controllerContext, ActionResult currentResult)
        {
            var viewResult = currentResult as ViewResult;

            if (viewResult == null)
                return null;

            var viewName = viewResult.ViewName.NullIfEmpty() 
                ?? controllerContext.RequestContext.RouteData.GetRequiredString("action");

            if (viewName.IsNullOrEmpty())
                throw new InvalidOperationException("View name cannot be null.");

            var partialViewName = string.Concat(partialViewPrefix, viewName);

            // check if partial exists, otherwise we'll use the same view
            var partialExists = viewResult.ViewEngineCollection.FindPartialView(controllerContext, partialViewName).View != null;

            var partialViewResult = new PartialViewResult
            {
                ViewData = viewResult.ViewData,
                TempData = viewResult.TempData,
                ViewName = partialExists ? partialViewName : viewName,
                ViewEngineCollection = viewResult.ViewEngineCollection,
            };

            return partialViewResult;
        }
示例#22
0
partial         void AfterUpdateData(SalesTeam e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
示例#23
0
 public Form(ActionResult result)
     : base(null)
 {
     this._result = result;
     this._formMethod = System.Web.Mvc.FormMethod.Post;
     _actionTypePassed = ActionTypePassed.HtmlActionResult;
 }
示例#24
0
partial         void AfterUpdateData(QualificationStudent e, ref ActionResult ar)
        {
            ar = this.Json(new AjaxOperationResult {
                Data = this.ToJson(e),
                Successful = true
            });
        }
        public void TestAddInvoiceDetails()
        {
            InvoiceDB db = new InvoiceDB();
            Invoice   i  = db.Invoices.First();

            ((IObjectContextAdapter)db).ObjectContext.Detach(i); //http://stackoverflow.com/questions/4168073/entity-framework-code-first-no-detach-method-on-dbcontext
            Assert.NotNull(i);

            InvoiceDetailsController idc = new InvoiceDetailsController();

            idc.ControllerContext = new ControllerContext()
            {
                HttpContext = new MockHttpContext()
            };

            InvoiceDetails id = new InvoiceDetails();

            id.TimeStamp = DateTime.Now;
            id.Invoice   = i;
            id.Qty       = 1;
            id.Price     = 100;
            id.VAT       = 18;
            id.Article   = "Invoice details test";

            //get
            System.Web.Mvc.ActionResult resultAddView = idc.Create(i.InvoiceID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultAddView);

            //post
            System.Web.Mvc.ActionResult resultAdd = idc.Create(id);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), resultAdd);

            Assert.AreEqual(((System.Web.Mvc.PartialViewResult)resultAdd).ViewName, "Index");
        }
示例#26
0
 private LoginResult(bool successful, string errorMessage, string accessToken, ActionResult defaultLoginAction)
 {
     Successful = successful;
     ErrorMessage = errorMessage;
     AccessToken = accessToken;
     DefaultLoginAction = defaultLoginAction;
 }
        /// <summary>
        /// 处理异常
        /// </summary>
        /// <param name="exception"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        private bool HandleException(Exception exception, out ActionResult result)
        {

            if (exception is ApiResultException)
            {
                var apiRet = ((ApiResultException)exception).Result;
                if (apiRet.code == 401)
                {
                    result = new RedirectResult("http://i.play7th.com/account/login?returnUrl=" + this.HttpContext.Request.Url.ToString());
                    return true;
                }
                if (this.HttpContext.Request.IsAjaxRequest())
                {
                    result = new JsonResult() { Data = (((ApiResultException)exception).Result), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                    return true;
                }
            }
            else if (exception is System.AggregateException)
            {
                exception = exception.InnerException;
                return this.HandleException(exception, out result);
            }
            else if (exception is EfException)
            {
                if (this.HttpContext.Request.IsAjaxRequest())
                {
                    result = new JsonResult() { Data = new ApiResult(7001, exception.Message), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }
            }
            result = null;
            return false;
        }
示例#28
0
        public void ShouldGoToJobListPage()
        {
            _result = _controller.List();

            Assert.That(_result, Is.InstanceOf<ViewResult>());
            Assert.That(ViewResult().ViewName, Is.EqualTo("Job"));
        }
示例#29
0
        public static MvcHtmlString ActionLinkWithFragment(this HtmlHelper htmlHelper, string text, ActionResult fragmentAction, string cssClass = null, string dataOptions = null)
        {
            var mvcActionResult = fragmentAction.AsMVCResult() as IMvcResult;

            if (mvcActionResult == null)
                return null;

            var options = string.Empty;

            var actionLink = string.Format("{0}#{1}",
                        RouteTable.Routes.GetVirtualPathForArea(htmlHelper.ViewContext.RequestContext,
                                                        new RouteValueDictionary(new
                                                        {
                                                            area = string.Empty,
                                                            controller = mvcActionResult.Controller,
                                                            action = string.Empty,
                                                        })).VirtualPath,
                         mvcActionResult.Action);

            if (!string.IsNullOrEmpty(dataOptions))
                options = "data-options=\"" + dataOptions.Trim() + "\"";

            return new MvcHtmlString(string.Format("<a id=\"{0}\" href=\"{1}\" class=\"jqAddress {2}\" {3}>{4}</a>", Guid.NewGuid(), actionLink,
                (string.IsNullOrEmpty(cssClass) ? string.Empty : cssClass.Trim()),
                (string.IsNullOrEmpty(options) ? string.Empty : options.Trim()), text));
        }
 public ActionResult ReturnRoute(int? id, ActionResult defaultRoute)
 {
     RouteValueDictionary routeValues = new RouteValueDictionary();
     switch (GetRouteParameter())
     {
         case "c-tls":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "TracksLocationsSlots";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "c-ss":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "SessionsSpeakers";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "c-m":
             routeValues["controller"] = "Conference";
             routeValues["action"] = "Manage";
             routeValues.Add("conferenceId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
         case "s-v":
             routeValues["controller"] = "Session";
             routeValues["action"] = "View";
             routeValues.Add("conferenceId", ControllerContext.HttpContext.Request.Params["ConferenceId"]);
             routeValues.Add("SessionId", id);
             return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues, ModuleContext));
     }
     return defaultRoute;
 }
示例#31
0
        public static ActionResult AddRouteValue(this ActionResult result, string name, object value)
        {
            RouteValueDictionary routeValues = result.GetRouteValueDictionary();

            ModelUnbinderHelpers.AddRouteValues(routeValues, name, value);
            return(result);
        }
        public void WhenIOpenTheDetailsOfBook(string bookId)
        {
            var book = ReferenceBooks.GetById(bookId);

            var controller = new CatalogController();
            actionResult = controller.Details(book.Id);
        }
        public void GoToActivityList()
        {
            var controller = CreateActivityController();

            var actionResult = controller.Index();          // No assert in the Given & When steps, please
            LatestActionResult = actionResult;
        }
示例#34
0
 public TempDataActionResult(ActionResult actionResult, string message, string classAlert, string classGlyphicon)
 {
     _actionResult = actionResult;
     _message = message;
     _classAlert = classAlert;
     _classGlyphicon = classGlyphicon;
 }
        public override System.Web.Mvc.ActionResult AjaxRedirect(System.Web.Mvc.ActionResult redirectAction)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.AjaxRedirect);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "redirectAction", redirectAction);
            AjaxRedirectOverride(callInfo, redirectAction);
            return(callInfo);
        }
示例#36
0
 /// <summary>
 /// Creates a notification, once the screen refreshes and will automatically appear based on Position.
 /// </summary>
 /// <param name="actionResult"></param>
 /// <param name="message"></param>
 /// <param name="position"></param>
 /// <param name="alertType"></param>
 /// <param name="timeOut">Time in milliseconds</param>
 /// <param name="animation"></param>
 /// <param name="modal"></param>
 /// <returns></returns>
 public static System.Web.Mvc.ActionResult WithNotification(
     this System.Web.Mvc.ActionResult actionResult, String message, Position position = Position.topRight,
     AlertType alertType = AlertType.information,
     int timeOut         = 2000,
     bool animation      = true,
     bool modal          = false)
 {
     return(new WithNotificationResult(actionResult, message, position, alertType, timeOut, animation, modal));
 }
        public override System.Web.Mvc.ActionResult RedirectToActionWithMessage(System.Web.Mvc.ActionResult redirectAction, RaceDay.PageMessageModel model)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.RedirectToActionWithMessage);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "redirectAction", redirectAction);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "model", model);
            RedirectToActionWithMessageOverride(callInfo, redirectAction, model);
            return(callInfo);
        }
示例#38
0
        public static IT4MVCActionResult GetT4MVCResult(this ActionResult result)
        {
            var t4MVCResult = result as IT4MVCActionResult;

            if (t4MVCResult == null)
            {
                throw new InvalidOperationException("T4MVC was called incorrectly. You may need to force it to regenerate by right clicking on T4MVC.tt and choosing Run Custom Tool");
            }
            return(t4MVCResult);
        }
示例#39
0
 public WithNotificationResult(System.Web.Mvc.ActionResult result,
                               String message, Position position, AlertType alertType, int timeOut, bool animation, bool modal)
 {
     this._result    = result;
     this._message   = message;
     this._position  = position;
     this._animation = animation;
     this._modal     = modal;
     this._alertType = alertType;
     this._timeout   = timeOut;
 }
示例#40
0
        public static ActionResult SecureAddRouteValues(this ActionResult result, RouteValueDictionary routeValues)
        {
            RouteValueDictionary currentRouteValues = result.GetRouteValueDictionary();

            // Add all the extra values
            foreach (var pair in routeValues)
            {
                ModelUnbinderHelpers.AddRouteValues(currentRouteValues, pair.Key, pair.Value);
            }

            return(result);
        }
示例#41
0
 public static ActionResult SecureAddRouteValues(this ActionResult result, System.Collections.Specialized.NameValueCollection nameValueCollection)
 {
     // Copy all the values from the NameValueCollection into the route dictionary
     if (nameValueCollection.AllKeys.Any(m => m == null))  //if it has a null, the CopyTo extension will crash!
     {
         var filtered = new System.Collections.Specialized.NameValueCollection(nameValueCollection);
         filtered.Remove(null);
         filtered.CopyTo(result.GetRouteValueDictionary());
     }
     else
     {
         nameValueCollection.CopyTo(result.GetRouteValueDictionary(), replaceEntries: true);
     }
     return(result);
 }
        public void TestEditInvoiceDetails()
        {
            InvoiceDetailsController idc = new InvoiceDetailsController();

            System.Web.Mvc.ViewResult result = idc.Index();

            InvoiceDetails id = ((List <InvoiceDetails>)result.ViewData.Model).First();

            System.Web.Mvc.ActionResult invoiceDetailsEdition = idc.Edit(id.InvoiceDetailsID);

            //post edited
            id.Price = 9999;

            System.Web.Mvc.ActionResult resultEdition = idc.Edit(id);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), resultEdition);
        }
示例#43
0
        public void TestDeleteInvoice()
        {
            InvoiceController ic = new InvoiceController();

            System.Web.Mvc.ViewResult result = ic.Index(null, null, null) as ViewResult;

            Invoice i = ((IPagedList <Invoice>)result.ViewData.Model).First();

            Assert.NotNull(i);

            //ask deletion action
            System.Web.Mvc.ActionResult invoiceAskDeletion = ic.Delete(i.InvoiceID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), invoiceAskDeletion);

            //delete action
            System.Web.Mvc.ActionResult invoiceDeletion = ic.DeleteConfirmed(i.InvoiceID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), invoiceDeletion);
        }
        public void TestDeleteInvoiceDetails()
        {
            InvoiceDetailsController idc = new InvoiceDetailsController();

            System.Web.Mvc.ViewResult result = idc.Index();

            InvoiceDetails id = ((List <InvoiceDetails>)result.ViewData.Model).First();

            Assert.NotNull(id);

            //ask deletion action
            System.Web.Mvc.ActionResult invoiceDetailsAskDeletion = idc.Delete(id.InvoiceDetailsID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.PartialViewResult), invoiceDetailsAskDeletion);

            //delete action
            System.Web.Mvc.ActionResult invoiceDetailDeletion = idc.DeleteConfirmed(id.InvoiceDetailsID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), invoiceDetailDeletion);
        }
示例#45
0
        public void TestEditInvoice()
        {
            InvoiceController ic     = new InvoiceController();
            ActionResult      result = ic.Index(null, null, null);
            ViewResult        view   = result as ViewResult;
            Invoice           i      = ((IPagedList <Invoice>)view.ViewData.Model).First();

            System.Web.Mvc.ActionResult invoiceEdition = ic.Edit(i.InvoiceID);

            //post edited
            i.Name = "Change invoice name test";

            //get
            System.Web.Mvc.ActionResult resultEditionView = ic.Edit(i.InvoiceID);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.ViewResult), resultEditionView);

            //post
            System.Web.Mvc.ActionResult resultEdition = ic.Edit(i);
            Assert.IsInstanceOf(typeof(System.Web.Mvc.RedirectToRouteResult), resultEdition);
        }
示例#46
0
        /// <summary>
        /// If specific route can be found, return that route with the parameter tokens in route string.
        /// </summary>
        public static string JavaScriptReplaceableUrl(this UrlHelper urlHelper, ActionResult result)
        {
            var    rvd  = result.GetRouteValueDictionary();
            string area = string.Empty;
            object token;

            if (rvd.TryGetValue("area", out token))
            {
                area = token.ToString();
            }

            if (!rvd.TryGetValue("controller", out token))
            {
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate controller in source dictionary");
            }
            string controller = token.ToString();

            if (!rvd.TryGetValue("SecureAction", out token))
            {
                throw new Exception("T4MVC JavascriptReplacableUrl could not locate SecureAction in source dictionary");
            }
            string SecureAction = token.ToString();

            // This matches the ActionResult to a specific route (so we can get the exact URL)
            string specificSecureActionUrl = RouteTable.Routes.OfType <Route>()
                                             .Where(r => r.DataTokens.CompareValue("area", area) &&
                                                    r.Defaults.CompareValue("controller", controller) &&
                                                    r.Defaults.CompareValue("SecureAction", SecureAction))
                                             .Select(r => r.Url)
                                             .FirstOrDefault();

            if (String.IsNullOrEmpty(specificSecureActionUrl))
            {
                return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary()));
            }

            return(urlHelper.Content("~/" + specificSecureActionUrl));
        }
示例#47
0
 partial void DeleteAndRedirectOverride(T4MVC_Framework_Mvc_ActionResults_RedirectToRouteWithTempDataResult callInfo, System.Action delete, System.Web.Mvc.ActionResult result);
示例#48
0
        public override Framework.Mvc.ActionResults.RedirectToRouteWithTempDataResult RedirectToFailureAction(System.Web.Mvc.ActionResult result, string message, bool openDialog)
        {
            var callInfo = new T4MVC_Framework_Mvc_ActionResults_RedirectToRouteWithTempDataResult(Area, Name, ActionNames.RedirectToFailureAction);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "result", result);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "message", message);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "openDialog", openDialog);
            RedirectToFailureActionOverride(callInfo, result, message, openDialog);
            return(callInfo);
        }
示例#49
0
 partial void RedirectToFailureActionOverride(T4MVC_Framework_Mvc_ActionResults_RedirectToRouteWithTempDataResult callInfo, System.Web.Mvc.ActionResult result, string message, bool openDialog);
示例#50
0
 partial void RedirectToSuccessActionOverride(T4MVC_Framework_Mvc_ActionResults_RedirectToRouteWithTempDataResult callInfo, System.Web.Mvc.ActionResult result, bool openDialog);
示例#51
0
 public static RouteValueDictionary GetRouteValueDictionary(this ActionResult result)
 {
     return(result.GetT4MVCResult().RouteValueDictionary);
 }
示例#52
0
        public static T GetModel <T>(System.Web.Mvc.ActionResult actionResult) where T : class
        {
            var asViewResult = actionResult as System.Web.Mvc.ViewResult;

            return(asViewResult.Model as T);
        }
示例#53
0
 public static MvcHtmlString SecureActionLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return(htmlHelper.RouteLink(linkText, null, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes));
 }
 partial void AjaxRedirectOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.Mvc.ActionResult redirectAction);
示例#55
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, object htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, null, result, htmlAttributes, null, null, null));
 }
 partial void RedirectToActionWithMessageOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, System.Web.Mvc.ActionResult redirectAction, RaceDay.PageMessageModel model);
示例#57
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, ActionResult result, object htmlAttributes, string protocol)
 {
     return(htmlHelper.RouteLink(linkText, routeName, result, htmlAttributes, protocol, null, null));
 }
示例#58
0
        public override Framework.Mvc.ActionResults.RedirectToRouteWithTempDataResult DeleteAndRedirect(System.Action delete, System.Web.Mvc.ActionResult result)
        {
            var callInfo = new T4MVC_Framework_Mvc_ActionResults_RedirectToRouteWithTempDataResult(Area, Name, ActionNames.DeleteAndRedirect);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "delete", delete);
            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "result", result);
            DeleteAndRedirectOverride(callInfo, delete, result);
            return(callInfo);
        }
示例#59
0
 public static ActionResult SecureAddRouteValues(this ActionResult result, object routeValues)
 {
     return(result.SecureAddRouteValues(new RouteValueDictionary(routeValues)));
 }
示例#60
0
 public static void AssertIsHttpNotFound(System.Web.Mvc.ActionResult actionResult)
 {
     Assert.IsInstanceOfType(actionResult, typeof(HttpNotFoundResult));
 }