Beispiel #1
0
        public virtual ActionResult Edit(string id, string version, EditPackageRequest formData, string returnUrl)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(HttpNotFound());
            }

            var user = _userService.FindByUsername(HttpContext.User.Identity.Name);

            if (user == null || !package.IsOwner(HttpContext.User))
            {
                return(new HttpStatusCodeResult(403, "Forbidden"));
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            // Add the edit request to a queue where it will be processed in the background.
            if (formData.Edit != null)
            {
                _editPackageService.StartEditPackageRequest(package, formData.Edit, user);
                _entitiesContext.SaveChanges();
            }

            return(Redirect(RedirectHelper.SafeRedirectUrl(Url, returnUrl ?? Url.Package(id, version))));
        }
Beispiel #2
0
        public virtual ActionResult Edit(string id, string version, EditPackageRequest formData, string returnUrl)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(HttpNotFound());
            }

            if (!package.IsOwner(User))
            {
                return(new HttpStatusCodeResult(403, "Forbidden"));
            }

            var user = GetCurrentUser();

            if (!ModelState.IsValid)
            {
                formData.PackageId    = package.PackageRegistration.Id;
                formData.PackageTitle = package.Title;
                formData.Version      = package.Version;

                var packageRegistration = _packageService.FindPackageRegistrationById(id);
                formData.PackageVersions = packageRegistration.Packages
                                           .OrderByDescending(p => new SemanticVersion(p.Version), Comparer <SemanticVersion> .Create((a, b) => a.CompareTo(b)))
                                           .ToList();

                return(View(formData));
            }

            // Add the edit request to a queue where it will be processed in the background.
            if (formData.Edit != null)
            {
                _editPackageService.StartEditPackageRequest(package, formData.Edit, user);
                _entitiesContext.SaveChanges();
            }

            return(SafeRedirect(returnUrl ?? Url.Package(id, version)));
        }
Beispiel #3
0
        public virtual async Task <ActionResult> Edit(string id, string version, EditPackageRequest formData, string returnUrl)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return(HttpNotFound());
            }

            if (!package.IsOwner(User))
            {
                return(new HttpStatusCodeResult(403, "Forbidden"));
            }

            var user = GetCurrentUser();

            if (!ModelState.IsValid)
            {
                return(EditFailed(id, formData, package));
            }

            // Add the edit request to a queue where it will be processed in the background.
            if (formData.Edit != null)
            {
                try
                {
                    _editPackageService.StartEditPackageRequest(package, formData.Edit, user);
                    await _entitiesContext.SaveChangesAsync();
                }
                catch (EntityException ex)
                {
                    ModelState.AddModelError("Edit.VersionTitle", ex.Message);

                    return(EditFailed(id, formData, package));
                }
            }

            return(SafeRedirect(returnUrl ?? Url.Package(id, version)));
        }