Example #1
0
        private Comparator GetComparator(Comparator request)
        {
            var        id    = request?.Id;
            Comparator ret   = null;
            var        query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetVisibleFields <Comparator>(currentUser, "Comparator", request.VisibleFields);

            DocEntityComparator entity = null;

            if (id.HasValue)
            {
                entity = DocEntityComparator.GetComparator(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No Comparator found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
Example #2
0
        public Comparator Post(ComparatorCopy request)
        {
            Comparator ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityComparator.GetComparator(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pDocumentSets = entity.DocumentSets.ToList();
                    var pName         = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var pURI = entity.URI;
                    if (!DocTools.IsNullOrEmpty(pURI))
                    {
                        pURI += " (Copy)";
                    }
                    #region Custom Before copyComparator
                    #endregion Custom Before copyComparator
                    var copy = new DocEntityComparator(ssn)
                    {
                        Hash   = Guid.NewGuid()
                        , Name = pName
                        , URI  = pURI
                    };
                    foreach (var item in pDocumentSets)
                    {
                        entity.DocumentSets.Add(item);
                    }

                    #region Custom After copyComparator
                    #endregion Custom After copyComparator
                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }