Ejemplo n.º 1
0
        public ActionResult Edit(Models.Symbol symbol, HttpPostedFileBase uploadFile, string[] packages)
        {
            symbol.SymbolPackages = new List <SymbolPackage>();
            if (packages != null)
            {
                foreach (var package in packages)
                {
                    symbol.SymbolPackages.Add(_symbolService.GetPackage(Guid.Parse(package)));
                }
            }
            ImageService img = new ImageService();

            if (uploadFile != null)
            {
                symbol.Thumbnail = img.SaveThumbnail(uploadFile, symbol);
            }

            Models.Symbol originalSymbol = _symbolService.GetSymbol(symbol.SystemId);

            ViewBag.IsAdmin = false;
            if (Request.IsAuthenticated)
            {
                ViewBag.IsAdmin = _authorizationService.IsAdmin();
            }

            if (!_authorizationService.HasAccess(originalSymbol.Owner,
                                                 ClaimsPrincipal.Current.GetOrganizationName()))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }


            if (ModelState.IsValid)
            {
                _symbolService.UpdateSymbol(originalSymbol, symbol);

                return(RedirectToAction("Index"));
            }

            ViewBag.Themes         = new SelectList(CodeList.Themes(), "Key", "Value", symbol.Theme);
            ViewBag.SymbolPackages = new MultiSelectList(_symbolService.GetPackagesWithAccessControl(), "SystemId", "Name", symbol.SymbolPackages.Select(c => c.SystemId).ToArray());


            return(View(symbol));
        }