#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.225
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace System.Web.WebPages.Administration.PackageManager
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Web;
    using System.Web.Helpers;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.WebPages;
    using System.Web.WebPages.Html;
    using System.Globalization;
    using NuGet;
    
    [System.Web.WebPages.PageVirtualPathAttribute("~/packages/Update.cshtml")]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorSingleFileGenerator", "1.0.0.0")]
    public class packages_Update_cshtml : System.Web.WebPages.WebPage
    {
#line hidden

                    // Resolve package relative syntax
                    // Also, if it comes from a static embedded resource, change the path accordingly
                    public override string Href(string virtualPath, params object[] pathParts) {
                        virtualPath = ApplicationPart.ProcessVirtualPath(GetType().Assembly, VirtualPath, virtualPath);
                        return base.Href(virtualPath, pathParts);
                    }
        public packages_Update_cshtml()
        {
        }
        protected System.Web.HttpApplication ApplicationInstance
        {
            get
            {
                return ((System.Web.HttpApplication)(Context.ApplicationInstance));
            }
        }
        public override void Execute()
        {


WriteLiteral("\r\n\r\n");




WriteLiteral("\r\n");


DefineSection("PackageHead", () => {

WriteLiteral(" \r\n    <script type=\"text/javascript\" src=\"");


                                   Write(Href("scripts/PackageAction.js"));

WriteLiteral("\"></script>\r\n    <noscript>");


         Write(PackageManagerResources.JavascriptRequired);

WriteLiteral("</noscript>\r\n");


});

WriteLiteral("\r\n");


  
    // Read params from request
    var sourceName = Request["source"];
    var packageId = Request["package"];
    var versionString = Request["version"];
    var packageSource = PageUtils.GetPackageSource(sourceName);

    var version = !versionString.IsEmpty() ? SemanticVersion.Parse(versionString) : null;
    
    WebProjectManager projectManager;
    try {
        projectManager = new WebProjectManager(packageSource.Source, PackageManagerModule.SiteRoot);
    } catch (Exception exception) {

WriteLiteral("        <div class=\"error message\">");


                              Write(exception.Message);

WriteLiteral("</div>\r\n");


        return;
    }
    var updatePackage = projectManager.SourceRepository.FindPackage(packageId, version);
    if (updatePackage == null) {
        ModelState.AddFormError(PackageManagerResources.BadRequest);
        
   Write(Html.ValidationSummary());

                                 
        return; 
    }

    var package = projectManager.LocalRepository.FindPackage(packageId);

    // Layout
    Page.SectionTitle = String.Format(CultureInfo.CurrentCulture, PackageManagerResources.UpdatePackageDesc, package.GetDisplayName(), updatePackage.Version);
    var packagesHomeUrl = Href(PageUtils.GetPackagesHome(), Request.Url.Query);

    if (IsPost) {
        AntiForgery.Validate();
        try { 
            projectManager.UpdatePackage(updatePackage);   
        } catch (Exception exception) {
            ModelState.AddFormError(exception.Message);
        }

        if (ModelState.IsValid) {
            Response.Redirect(packagesHomeUrl + "&action-completed=Update");
        }
        else {
            
       Write(Html.ValidationSummary(String.Format(CultureInfo.CurrentCulture, PackageManagerResources.PackageUpdateError, package.GetDisplayName())));

                                                                                                                                                    
        }
        return;
    }


WriteLiteral("\r\n");


Write(RenderPage("_PackageDetails.cshtml", new Dictionary<string, object>{ {"Package", updatePackage} }));

WriteLiteral("\r\n<br />\r\n<form method=\"post\" action=\"\" id=\"submitForm\">\r\n    ");


Write(AntiForgery.GetHtml());

WriteLiteral("\r\n    <input type=\"hidden\" name=\"source\" value=\"");


                                         Write(sourceName);

WriteLiteral("\" />\r\n    <input type=\"hidden\" name=\"package\" value=\"");


                                          Write(packageId);

WriteLiteral("\" />\r\n    <input type=\"hidden\" name=\"version\" value=\"");


                                          Write(version);

WriteLiteral("\" />\r\n\r\n    <input type=\"submit\" value=\"");


                           Write(PackageManagerResources.UpdatePackage);

WriteLiteral("\" />\r\n    <input type=\"reset\" value=\"");


                          Write(PackageManagerResources.Cancel);

WriteLiteral("\" data-returnurl=\"");


                                                                           Write(packagesHomeUrl);

WriteLiteral("\" />\r\n    <br /><br />\r\n</form>");


        }
    }
}
#pragma warning restore 1591
