Ejemplo n.º 1
0
        private UserType GetUserType(UserType request)
        {
            var      id    = request?.Id;
            UserType ret   = null;
            var      query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityUserType entity = null;

            if (id.HasValue)
            {
                entity = DocEntityUserType.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No UserType 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.º 2
0
        public UserType Post(UserTypeCopy request)
        {
            UserType ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityUserType.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 pPayrollStatus = entity.PayrollStatus;
                    var pPayrollType   = entity.PayrollType;
                    var pType          = entity.Type;
                    var pUsers         = entity.Users.ToList();
                    var copy           = new DocEntityUserType(ssn)
                    {
                        Hash            = Guid.NewGuid()
                        , PayrollStatus = pPayrollStatus
                        , PayrollType   = pPayrollType
                        , Type          = pType
                    };
                    foreach (var item in pUsers)
                    {
                        entity.Users.Add(item);
                    }

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