示例#1
0
        private void ValidationName(Models.Register subRegister, Models.Register originalRegister)
        {
            var seoName = Helpers.RegisterUrls.MakeSeoFriendlyString(subRegister.name, subRegister.TransliterNorwegian);

            subRegister.pathOld = RegisterUrls.GetNewPath(originalRegister.pathOld, seoName);
            subRegister.path    = RegisterUrls.GetNewPath(originalRegister.path, seoName);


            var queryResultsDataset = from o in _db.Registers
                                      where o.systemId != subRegister.systemId && (o.path == subRegister.pathOld || o.path == subRegister.path)
                                      select o.systemId;

            if (queryResultsDataset.Count() > 0)
            {
                ModelState.AddModelError("ErrorMessage", Registers.ErrorMessageValidationName);
            }
        }
示例#2
0
        //[Route("subregister/{registername}/{registerOwner}/{subregister}/rediger")]
        public ActionResult Edit(Models.Register register, string registername, DateTime?itemsValidFrom, DateTime?itemsValidTo)
        {
            var originalRegister = _registerService.GetRegisterBySystemId(register.systemId);

            if (_accessControlService.HasAccessTo(originalRegister))
            {
                ValidationName(register, originalRegister);

                if (ModelState.IsValid)
                {
                    if (register.name != null)
                    {
                        originalRegister.name = register.name;
                    }
                    originalRegister.seoname = Helpers.RegisterUrls.MakeSeoFriendlyString(originalRegister.name, register.TransliterNorwegian);
                    var pathOld = originalRegister.path;
                    var transliterNorwegianOld = originalRegister.TransliterNorwegian;
                    originalRegister.path = RegisterUrls.GetNewPath(originalRegister.path, originalRegister.seoname);
                    if (register.description != null)
                    {
                        originalRegister.description = register.description;
                    }
                    if (register.ownerId != null)
                    {
                        originalRegister.ownerId = register.ownerId;
                    }
                    if (register.managerId != null)
                    {
                        originalRegister.managerId = register.managerId;
                    }
                    if (register.targetNamespace != null)
                    {
                        originalRegister.targetNamespace = register.targetNamespace;
                    }
                    originalRegister.accessId         = register.accessId;
                    originalRegister.parentRegisterId = register.parentRegisterId;


                    originalRegister.modified = DateTime.Now;
                    if (register.statusId != null)
                    {
                        originalRegister.statusId = register.statusId;
                        if (originalRegister.statusId != "Valid" && register.statusId == "Valid")
                        {
                            originalRegister.dateAccepted = DateTime.Now;
                        }

                        if (originalRegister.statusId == "Valid" && register.statusId != "Valid")
                        {
                            originalRegister.dateAccepted = null;
                        }
                    }

                    originalRegister.MakeAllItemsValid = register.MakeAllItemsValid;
                    if (originalRegister.MakeAllItemsValid)
                    {
                        _registerItemService.MakeAllRegisterItemsValid(originalRegister, itemsValidFrom, itemsValidTo);
                    }
                    originalRegister.MakeAllItemsRetired = register.MakeAllItemsRetired;
                    if (originalRegister.MakeAllItemsRetired)
                    {
                        _registerItemService.MakeAllRegisterItemsRetired(originalRegister);
                    }
                    originalRegister.MakeAllItemsDraft = register.MakeAllItemsDraft;
                    if (originalRegister.MakeAllItemsDraft)
                    {
                        _registerItemService.MakeAllRegisterItemsDraft(originalRegister);
                    }
                    originalRegister.TransliterNorwegian = register.TransliterNorwegian;
                    _translationService.UpdateTranslations(register, originalRegister);
                    _db.Entry(originalRegister).State = EntityState.Modified;
                    _db.SaveChanges();

                    if (pathOld != originalRegister.path || transliterNorwegianOld != originalRegister.TransliterNorwegian)
                    {
                        new SynchronizationService(_db).UpdatePaths(originalRegister.systemId.ToString(), originalRegister.TransliterNorwegian);
                    }

                    Viewbags(register);

                    return(Redirect(originalRegister.GetObjectUrl()));
                }
            }
            else
            {
                throw new HttpException(401, "Access Denied");
            }

            Viewbags(register);
            return(View(originalRegister));
        }