public async Task <IActionResult> Edit(Guid id, [Bind("Id,ProductReference,ProductOwner,ParentId")] ProductGroup productGroup)
        {
            if (id == default(Guid))
            {
                return(NotFound());
            }
            else if ([email protected])
            {
                return(Unauthorized());
            }
            else if (!ModelState.IsValid)
            {
                ViewBag.Products = _productGroupRepository.GetSelectList();

                return(View(productGroup));
            }
            else if (!await _authRepository.IsAuthedRole(@User.Identity.Name.Substring(@User.Identity.Name.IndexOf(@"\") + 1)))
            {
                ViewBag.Products    = _productGroupRepository.GetSelectList();
                ViewBag.UserMessage = "You are not authorised to edit this product Group. Please contact your local customer relationship manager.";

                return(View(productGroup));
            }

            try
            {
                if (await CheckPartents(id, productGroup.ParentId) || await CheckChildren(id, productGroup.Id))
                {
                    ViewBag.Products    = _productGroupRepository.GetSelectList();
                    ViewBag.UserMessage = "Cant be own Ancestor.";

                    return(View(productGroup));
                }

                await _productGroupRepository.Put(productGroup);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!await _productGroupRepository.Exists(productGroup.Id))
                {
                    return(NotFound());
                }
                else
                {
                    _logger.LogCritical(500, ex.Message, ex);

                    return(StatusCode(500, ex.Message));
                }
            }

            try
            {
                await _legacyFileRepository.Publish();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(500, ex.Message, ex);

                return(StatusCode(500, ex.Message));
            }
        }