Ejemplo n.º 1
0
        public void Delete(UnitConversionRules request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityUnitConversionRules.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No UnitConversionRules could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

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

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.UNITCONVERSIONRULES);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Ejemplo n.º 2
0
        private UnitConversionRules GetUnitConversionRules(UnitConversionRules request)
        {
            var id = request?.Id;
            UnitConversionRules ret = null;
            var query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <UnitConversionRules>(currentUser, "UnitConversionRules", request.Select);

            DocEntityUnitConversionRules entity = null;

            if (id.HasValue)
            {
                entity = DocEntityUnitConversionRules.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No UnitConversionRules 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);
        }
Ejemplo n.º 3
0
        public UnitConversionRules Post(UnitConversionRulesCopy request)
        {
            UnitConversionRules ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityUnitConversionRules.Get(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 pDestinationUnit = entity.DestinationUnit;
                    var pIsDefault       = entity.IsDefault;
                    var pIsDestinationSi = entity.IsDestinationSi;
                    var pModifierTerm    = entity.ModifierTerm;
                    var pMultiplier      = entity.Multiplier;
                    var pParent          = entity.Parent;
                    var pRootTerm        = entity.RootTerm;
                    var pSourceUnit      = entity.SourceUnit;
                    var copy             = new DocEntityUnitConversionRules(ssn)
                    {
                        Hash = Guid.NewGuid()
                        , DestinationUnit = pDestinationUnit
                        , IsDefault       = pIsDefault
                        , IsDestinationSi = pIsDestinationSi
                        , ModifierTerm    = pModifierTerm
                        , Multiplier      = pMultiplier
                        , Parent          = pParent
                        , RootTerm        = pRootTerm
                        , SourceUnit      = pSourceUnit
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }